EGOCMS  24.0
EGOTEC Content-Managament-System
Ego_RSS.php
gehe zur Dokumentation dieser Datei
1 <?php
14 class Ego_RSS {
19  private $url = '';
20 
26  private $external = true;
27 
33  public function __construct($url) {
34  if (
35  $GLOBALS['egotec_conf']['proxy']['proxy_host']
36  && $GLOBALS['egotec_conf']['proxy']['proxy_port']
37  ) {
38  // Bei einem Proxy muss die Datei heruntergeladen werden
39  if ($content = Ego_System::file_get_contents($url)) {
40  $tmp = $GLOBALS['egotec_conf']['tmp_dir'].'RSS'.md5(microtime()).'.rss';
41  file_put_contents($tmp, $content);
42  $this->url = $tmp;
43  $this->external = false;
44  }
45  } else {
46  $this->url = $url;
47  }
48  }
49 
53  public function __destruct() {
54  if (!$this->external) {
55  @unlink($this->url);
56  }
57  }
58 
65  public function read($max = 0) {
66  require_once('SimplePie/autoloader.php');
67  $content = array();
68 
69  if (!empty($this->url)) {
70  $feed = new SimplePie();
71  $feed->set_feed_url($this->url);
72  $feed->enable_cache(false);
73  if ($feed->init()) {
74  $feed->handle_content_type();
75 
76  foreach ($feed->get_items() as $item) {
77  if (!$max || sizeof($content) < $max) {
78  $content[] = array(
79  'link' => $item->get_permalink(),
80  'title' => $item->get_title(),
81  'description' => $item->get_description(),
82  'date' => $item->get_date('Y-m-d H:i:s')
83  );
84  } else {
85  break;
86  }
87  }
88  }
89  }
90  return $content;
91  }
92 }
93 ?>
__destruct()
Definition: Ego_RSS.php:53
read($max=0)
Definition: Ego_RSS.php:65
__construct($url)
Definition: Ego_RSS.php:33
static file_get_contents($filename, $utf8=true, $context=null)