Commit | Line | Data |
---|---|---|
bc13d5d6 H |
1 | <?php |
2 | ini_set("include_path","/home/hromi1/kyberia/inc:/home/hromi1/kyberia/boxiky/"); | |
3 | include_once("kyberia.inc"); | |
4 | $kyberia = new CLASS_KYBERIA(); | |
5 | ||
6 | function strip_http_headers($text) { | |
7 | $text = str_replace("\r\n","\n",$text); | |
8 | $pozice = strpos($text,"\n\n"); | |
9 | $text = trim(substr($text,$pozice+0,strlen($text))); | |
10 | return $text; | |
11 | } | |
12 | ||
13 | function unhtmlspecialchars($str) { | |
14 | $trans = get_html_translation_table(HTML_SPECIALCHARS); | |
15 | $trans = array_flip($trans); | |
16 | return strtr($str, $trans); | |
17 | } | |
18 | ||
19 | ||
20 | function steal($url) { | |
21 | $url=str_replace("http://","",$url); | |
22 | $i=strpos($url,"/"); | |
23 | $hostname=substr($url,0,$i); | |
24 | $filename=substr($url,$i); | |
25 | $fp = fsockopen ($hostname, 80, $errno, $errstr, 30); | |
26 | if (!$fp) { | |
27 | echo "$errstr ($errno)<br>\n"; | |
28 | } else { | |
29 | fputs ($fp, "GET /$filename HTTP/1.0\r\nHost: $hostname\r\n\r\n"); | |
30 | while (!feof($fp)) { | |
31 | $rssdata.= fgets ($fp,128); | |
32 | } | |
33 | fclose ($fp); | |
34 | return $rssdata; | |
35 | } | |
36 | ||
37 | } | |
38 | ||
39 | $rssdata=steal($_GET['datafeed']); | |
40 | $rssdata=strip_http_headers($rssdata); | |
41 | $rssdata=urldecode($rssdata); | |
42 | include_once("xml/xmlarray.inc"); | |
43 | ||
44 | if (strstr($rssdata,"<rss")) $capsule="rss"; | |
45 | if (strstr($rssdata,"<rdf:RDF")) $capsule="rdf:RDF"; | |
46 | $parser = new xmlarray("",$capsule); | |
47 | $pole=$parser->parse($rssdata); | |
48 | print_r($pole); | |
49 | if (empty($pole['channel']['item'])) $pole['channel']['item']=$pole['item']; | |
50 | foreach ($pole['channel']['item'] as $item) { | |
51 | echo $item['title']."<br>"; | |
52 | if (! empty($item["link"])) { | |
53 | $md5=md5($item['link']); | |
54 | $set=$kyberia->executeQuery("select * from rss_news where news_md5='$md5'"); | |
55 | if (!$set->getNumRows()) { | |
56 | $q="INSERT INTO rss_news set news_source='3',"; | |
57 | $q.="news_title='".addSlashes(unhtmlspecialchars($item["title"]))."',"; | |
58 | $q.="news_url='".addSlashes(unhtmlspecialchars($item["link"]))."'"; | |
59 | $q.=",news_md5='$md5'"; | |
60 | echo "<br>"; | |
61 | echo "<a class=box href='",$item["link"],"'>"; | |
62 | echo $item["title"],"</a>\n"; | |
63 | if (!empty($item["description"])) { | |
64 | ||
65 | $q.=",news_desc='".addSlashes(strip_tags(unhtmlspecialchars($item['description'])))."'"; | |
66 | echo "<br><b>",$item['description'],"</b><br>"; | |
67 | } | |
68 | if (!empty($item['image'])) { | |
69 | if (!empty($item['image']['title'])) $q.=",news_image_title='".addSlashes(unhtmlspecialchars($item['image']['title']))."'"; | |
70 | ||
71 | if (!empty($item['image']['link'])) $q.=",news_image_link='".addSlashes(unhtmlspecialchars($item['image']['link']))."'"; | |
72 | if (!empty($item['image']['url'])) $q.=",news_image='".addSlashes(unhtmlspecialchars($item['image']['url']))."'"; | |
73 | } | |
74 | ||
75 | elseif (!empty($pole['image'])) { | |
76 | $q.=",news_image_title='".addSlashes(unhtmlspecialchars($pole['image']['title']))."'"; | |
77 | $q.=",news_image_link='".addSlashes(unhtmlspecialchars($pole['image']['link']))."'"; | |
78 | $q.=",news_image='".addSlashes(unhtmlspecialchars($pole['image']['url']))."'"; | |
79 | } | |
80 | else { | |
81 | $q.=",news_image_title='".addSlashes(unhtmlspecialchars($pole['channel']['image']['title']))."'"; | |
82 | $q.=",news_image_link='".addSlashes(unhtmlspecialchars($pole['channel']['image']['link']))."'"; | |
83 | $q.=",news_image='".addSlashes(unhtmlspecialchars($pole['channel']['image']['url']))."'"; | |
84 | } | |
85 | ||
86 | ||
87 | $kyberia->executeUpdate($q); | |
88 | ||
89 | } | |
90 | } | |
91 | } | |
92 | ||
93 | ||
94 | ||
95 | ?> |