source: trunk/Modules/News/ImportZdechovCzNews.php@ 839

Last change on this file since 839 was 827, checked in by chronos, 9 years ago
  • Fixed: External news parsing scripts used wrong application class name.
  • Property svn:executable set to *
File size: 1.7 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Application/System.php');
4$System = new Core();
5$System->ShowPage = false;
6$System->Run();
7
8$SourceURL = 'http://www.zdechov.cz/';
9$StartText = '<tr class="even">';
10$StartLink = 'href="';
11$StartTitle = '>';
12$TitleSeparator = '"';
13$StartDescription = '';
14$StartDate = '<td align="right">';
15$Category = 12;
16$Author = 'Automat';
17$Content = @file_get_contents($SourceURL);
18while(strpos($Content, $StartText) !== false)
19{
20 $Content = substr($Content, strpos($Content, $StartText) + strlen($StartText));
21 $Content = substr($Content, strpos($Content, $StartDate) + strlen($StartDate));
22 $Date = substr($Content, 0, strpos($Content, '<'));
23 $DateParts = explode('.', $Date);
24 $Date = $DateParts[2].'-'.$DateParts[1].'-'.$DateParts[0];
25 $Content = substr($Content, strpos($Content, $StartLink) + strlen($StartLink));
26 $Link = substr($Content, 0, strpos($Content, '"'));
27 if(substr($Link, 0, 7) != 'http://') $Link = 'http://www.zdechov.cz/'.$Link;
28 $Content = substr($Content, strpos($Content, $StartTitle) + strlen($StartTitle));
29 $Title = substr($Content, 0, strpos($Content, '<'));
30 $Description = '';
31
32
33 /*
34 echo('Title: '.$Title.'<br>');
35 echo('Description: '.$Description.'<br>');
36 echo('Date: '.$Date.'<br>');
37 echo('Link: '.$Link.'<br><hr>');
38 */
39
40 $DbResult = $System->Database->select('News', 'Id', '`Title`="'.$System->Database->real_escape_string($Title).'" AND `Date`="'.$Date.'" AND `Category`='.$Category);
41 //echo($System->Database->LastQuery);
42 if($DbResult->num_rows == 0)
43 {
44 $System->Database->insert('News', array('Title' => $Title, 'Date' => $Date, 'Author' => $Author, 'Category' => $Category, 'Content' => $Description, 'Link' => $Link));
45 echo($System->Database->insert_id.',');
46 }
47}
Note: See TracBrowser for help on using the repository browser.