1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/../../Common/Global.php');
|
---|
4 |
|
---|
5 | $SourceURL = 'http://www.obec-hovezi.cz/web/rss.xml';
|
---|
6 | $StartText = '<item>';
|
---|
7 | $TitleSeparator = '<title>';
|
---|
8 | $DescriptionSeparator = '<description>';
|
---|
9 | $StartLink = '<link>';
|
---|
10 | $Category = 16;
|
---|
11 | $Author = 'Automat';
|
---|
12 |
|
---|
13 | $doc = new DOMDocument();
|
---|
14 | $doc->load($SourceURL);
|
---|
15 | foreach($doc->getElementsByTagName('item') as $node)
|
---|
16 | {
|
---|
17 | $Title = $node->getElementsByTagName('title')->item(0)->nodeValue;
|
---|
18 | $Description = $node->getElementsByTagName('description')->item(0)->nodeValue;
|
---|
19 | $Link = $node->getElementsByTagName('link')->item(0)->nodeValue;
|
---|
20 | $Date = $node->getElementsByTagName('pubDate')->item(0)->nodeValue;
|
---|
21 |
|
---|
22 | $Description = strip_tags($Description);
|
---|
23 | $Description = str_replace("\r", '', $Description);
|
---|
24 | $Description = str_replace("\n", '<br>', $Description);
|
---|
25 | //if(($CommaPos = strpos($Date, ',')) !== FALSE)
|
---|
26 | // $Date = substr($Date, $CommaPos + 1);
|
---|
27 | $Date = TimeToMysqlDateTime(strtotime($Date));
|
---|
28 |
|
---|
29 |
|
---|
30 | $DbResult = $System->Database->select('News', 'Id', '(`Title`="'.$System->Database->real_escape_string($Title).'") AND (`Category`='.$Category.') AND (`Content` = "'.$System->Database->real_escape_string($Description).'") AND (`Link` = "'.$System->Database->real_escape_string($Link).'")');
|
---|
31 | //echo($System->Database->LastQuery);
|
---|
32 | if($DbResult->num_rows == 0)
|
---|
33 | {
|
---|
34 | $System->Database->insert('News', array('Title' => $Title, 'Date' => $Date, 'Author' => $Author, 'Category' => $Category, 'Content' => $Description, 'Link' => $Link));
|
---|
35 | echo($System->Database->insert_id.',');
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | /*
|
---|
40 | //$Content = addslashes(ToUTF8(file_get_contents($SourceURL), 'win1250'));
|
---|
41 | $Content = file_get_contents($SourceURL);
|
---|
42 | while(strpos($Content, $StartText) !== false)
|
---|
43 | {
|
---|
44 | $Content = substr($Content, strpos($Content, $StartText) + strlen($StartText));
|
---|
45 | $Title = substr($Content, strpos($Content, $TitleSeparator) + strlen($TitleSeparator));
|
---|
46 | $Title = substr($Title, 0, strpos($Title, '<'));
|
---|
47 |
|
---|
48 | $Description = substr($Content, strpos($Content, $DescriptionSeparator) + strlen($DescriptionSeparator));
|
---|
49 | $Description = trim(substr($Description, 0, strpos($Description, '</')));
|
---|
50 |
|
---|
51 | $Content = substr($Content, strpos($Content, $StartLink) + strlen($StartLink));
|
---|
52 | $Link = substr($Content, 0, strpos($Content, '<'));
|
---|
53 | // $Link = substr($Link, 0, strpos($Link, '?')); // Remove URL parameters
|
---|
54 | // $Link = substr($Link, 0, strrpos($Link, '/')).substr($Link, strrpos($Link, '/')); // Insert month between folder and filename
|
---|
55 | // $Description .= '<br><a href="'.$Link.'">Video</a>';
|
---|
56 |
|
---|
57 | //echo('Title: '.$Title.'<br>');
|
---|
58 | //echo('Description: '.$Description.'<br>');
|
---|
59 | //echo('Link: '.$Link.'<br><hr>');
|
---|
60 |
|
---|
61 | $Link = $System->Database->real_escape_string($Link);
|
---|
62 | $Title = $System->Database->real_escape_string($Title);
|
---|
63 | $Description = strip_cdata($Description);
|
---|
64 | $Description = strip_tags($Description);
|
---|
65 |
|
---|
66 | $Description = str_replace("\n", '<br>', $Description);
|
---|
67 | $Description = str_replace("\r", '', $Description);
|
---|
68 | $Description = $System->Database->real_escape_string($Description);
|
---|
69 |
|
---|
70 | $DbResult = $System->Database->select('News', 'Id', '(`Title`="'.$Title.'") AND (`Category`='.$Category.') AND (`Content` = "'.$Description.'") AND (`Link` = "'.$Link.'")');
|
---|
71 | //echo($System->Database->LastQuery);
|
---|
72 | if($DbResult->num_rows == 0)
|
---|
73 | {
|
---|
74 | $System->Database->insert('News', array('Title' => $Title, 'Date' => 'NOW()', 'Author' => $Author, 'Category' => $Category, 'Content' => $Description, 'Link' => $Link));
|
---|
75 | echo($System->Database->insert_id.',');
|
---|
76 | }
|
---|
77 | }
|
---|
78 | */
|
---|
79 |
|
---|
80 | ?>
|
---|