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