1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<?php
function html2txt($document){ $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA ); $text = preg_replace($search, '', $document);
$search = array('?', 'î', 'â', '„', ' '); $replace = array('a', 'i', 'a', '"', ' ');
$textf = str_replace($search, $replace, $text);
return $textf; }
require_once("/var/www/sites/kptv.ro/public_html/radio/conf_/siteconf_.php"); $datenow = date(DATE_RFC2822);
$rss = '<?xml version="1.0" encoding="ISO-8859-2" ?>'; $rss .= '<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/rss/nolsol.xsl"?>'; //$rss = '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'; $rss .= '<rss version="2.0"> <channel>'; $rss .= '<title>KPTV | THE ROCK STATION</title>'; $rss .= '<link>http://radio.kptv.ro</link>'; //$rss .= '<atom:link href="http://radio.kptv.ro/rss/rss.xml" rel="self" type="application/rss+xml" />'; $rss .= '<description>The Rock Station</description>'; $rss .= '<language>ro</language>'; $rss .= '<lastBuildDate>'.$datenow.'</lastBuildDate>'; $rss .= '<copyright>Copyright: (C) KPTV 2012</copyright>'; $rss .= '<ttl>30</ttl>'; $rss .= '<image>'; $rss .= '<title>KPTV | THE ROCK STATION</title>'; $rss .= '<url>http://radio.kptv.ro/images/logo.gif</url>'; $rss .= '<link>http://radio.kptv.ro</link>'; $rss .= '</image>';
$conn = mysql_connect($db_host, $db_usrName, $db_password);
if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db($db_name)) { echo "Unable to select mydbname: " . mysql_error(); exit; }
$sql = "SELECT *, DATE_FORMAT(Datas,'%a, %d %b %Y %T') AS rfcpubdate FROM stiri WHERE Activs = 1 ORDER BY Stickys DESC, Datas DESC LIMIT 15";
$result = mysql_query($sql);
if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; }
if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; }
// While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { $rss .= '<item>'; $rss .= '<title>'.$row["Titlu"].'</title>'; $rss .= '<description>'. strip_tags (html2txt(substr($row["Continut"], 0, 700))).'</description>'; //$rss .= '<description>'. normal_chars(substr($row["Continut"], 0, 700)).'</description>'; $rss .= '<link>http://radio.kptv.ro/ro/index.php?pg=stire&id='.$row["ID"].'</link>'; $rss .= '<guid isPermaLink="false">http://radio.kptv.ro/ro/index.php?pg=stire&id='.$row["ID"].'</guid>'; $rss .= '<pubDate>'.$row["rfcpubdate"]." ".date('O').'</pubDate>'; $rss .= '<category>News</category>'; $rss .= '</item>'; }
mysql_free_result($result);
$rss .= '</channel>'; $rss .= '</rss>';
$filename = '/var/www/sites/kptv.ro/public_html/radio/rss/rss.xml';
// Let's make sure the file exists and is writable first. if (is_writable($filename)) {
// In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; }
// Write $somecontent to our opened file. if (fwrite($handle, $rss) === FALSE) { echo "Cannot write to file ($filename)"; exit; }
echo "Success, wrote to file ($filename)";
fclose($handle);
} else { echo "The file $filename is not writable"; }
?>
|