ILIAS  release_7 Revision v7.30-3-g800a261c036
ilExternalFeed Class Reference

Handles external Feeds via Magpie library. More...

+ Collaboration diagram for ilExternalFeed:

Public Member Functions

 __construct ()
 Constructor. More...
 
 setUrl ($a_url)
 Set Url. More...
 
 getUrl ()
 Get Url. More...
 
 setError ($a_error)
 Set Error. More...
 
 getError ()
 Get Error. More...
 
 fetch ()
 Fetch the feed. More...
 
 checkCacheHit ()
 Check cache hit. More...
 
 getChannelTitle ()
 Get Channel. More...
 
 getChannelDescription ()
 Get Description. More...
 
 getItems ()
 Get Items. More...
 

Static Public Member Functions

static _createCacheDirectory ()
 Create magpie cache directorry (if not existing) More...
 
static _checkUrl ($a_url)
 Check Url. More...
 
static _determineFeedUrl ($a_url)
 Determine Feed Url. More...
 
static _getRSSLocation ($html, $location)
 This one is by Keith Devens , see http://keithdevens.com/weblog/archive/2002/Jun/03/RSSAuto-DiscoveryPHP. More...
 

Protected Attributes

 $items = array()
 

Detailed Description

Handles external Feeds via Magpie library.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 27 of file class.ilExternalFeed.php.

Constructor & Destructor Documentation

◆ __construct()

ilExternalFeed::__construct ( )

Constructor.

Definition at line 34 of file class.ilExternalFeed.php.

References _createCacheDirectory(), and ilProxySettings\_getInstance().

35  {
36  // IF YOU ADD THINGS HERE, THEY MAY ALSO BE ADDED TO
37  // SOME OF THE STATIC METHODS
38  $this->_createCacheDirectory();
39 
40  if (ilProxySettings::_getInstance()->isActive()) {
41  define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
42  define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
43  } else {
44  define('IL_FEED_PROXY_HOST', "");
45  define('IL_FEED_PROXY_PORT', "");
46  }
47  }
static _createCacheDirectory()
Create magpie cache directorry (if not existing)
static _getInstance()
Getter for unique instance.
+ Here is the call graph for this function:

Member Function Documentation

◆ _checkUrl()

static ilExternalFeed::_checkUrl (   $a_url)
static

Check Url.

Parameters
stringURL
Returns
mixed true, if everything is fine, error string otherwise

Definition at line 105 of file class.ilExternalFeed.php.

References _createCacheDirectory(), and ilProxySettings\_getInstance().

Referenced by ilFeedUrlInputGUI\checkInput().

106  {
107  if (!defined('IL_FEED_PROXY_HOST')) {
109 
110  if (ilProxySettings::_getInstance()->isActive()) {
111  define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
112  define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
113  } else {
114  define('IL_FEED_PROXY_HOST', "");
115  define('IL_FEED_PROXY_PORT', "");
116  }
117  }
118 
119  $feed = @fetch_rss($a_url);
120  if (!$feed) {
121  $error = magpie_error();
122 
123  if ($error != "") {
124  return $error;
125  } else {
126  return "Unknown Error.";
127  }
128  }
129 
130  return true;
131  }
static _createCacheDirectory()
Create magpie cache directorry (if not existing)
static _getInstance()
Getter for unique instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createCacheDirectory()

static ilExternalFeed::_createCacheDirectory ( )
static

Create magpie cache directorry (if not existing)

Definition at line 92 of file class.ilExternalFeed.php.

References ilUtil\getDataDir(), and ilUtil\makeDir().

Referenced by __construct(), _checkUrl(), and checkCacheHit().

93  {
94  if (!is_dir(ilUtil::getDataDir() . "/magpie_cache")) {
95  ilUtil::makeDir(ilUtil::getDataDir() . "/magpie_cache");
96  }
97  }
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getDataDir()
get data directory (outside webspace)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _determineFeedUrl()

static ilExternalFeed::_determineFeedUrl (   $a_url)
static

Determine Feed Url.

Parameters
$a_urlURL that

Definition at line 219 of file class.ilExternalFeed.php.

References $res, ilProxySettings\_getInstance(), and _getRSSLocation().

Referenced by ilFeedUrlInputGUI\checkInput().

220  {
221  if (!defined('IL_FEED_PROXY_HOST')) {
222  if (ilProxySettings::_getInstance()->isActive()) {
223  define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
224  define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
225  } else {
226  define('IL_FEED_PROXY_HOST', "");
227  define('IL_FEED_PROXY_PORT', "");
228  }
229  }
230 
231  $res = @fopen($a_url, "r");
232 
233  if (!$res) {
234  return "";
235  }
236 
237  $contents = '';
238  while (!feof($res)) {
239  $contents .= fread($res, 8192);
240  }
241  fclose($res);
242 
243  return ilExternalFeed::_getRSSLocation($contents, $a_url);
244  }
foreach($_POST as $key=> $value) $res
static _getRSSLocation($html, $location)
This one is by Keith Devens , see http://keithdevens.com/weblog/archive/2002/Jun/03/RSSAuto-Discovery...
static _getInstance()
Getter for unique instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getRSSLocation()

static ilExternalFeed::_getRSSLocation (   $html,
  $location 
)
static

This one is by Keith Devens , see http://keithdevens.com/weblog/archive/2002/Jun/03/RSSAuto-DiscoveryPHP.

Definition at line 250 of file class.ilExternalFeed.php.

References $attributes, $location, and $n.

Referenced by _determineFeedUrl().

251  {
252  if (!$html or !$location) {
253  return false;
254  } else {
255  #search through the HTML, save all <link> tags
256  # and store each link's attributes in an associative array
257  preg_match_all('/<link\s+(.*?)\s*\/?>/si', $html, $matches);
258  $links = $matches[1];
259  $final_links = array();
260  $link_count = count($links);
261  for ($n = 0; $n < $link_count; $n++) {
262  $attributes = preg_split('/\s+/s', $links[$n]);
263  foreach ($attributes as $attribute) {
264  $att = preg_split('/\s*=\s*/s', $attribute, 2);
265  if (isset($att[1])) {
266  $att[1] = preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]);
267  $final_link[strtolower($att[0])] = $att[1];
268  }
269  }
270  $final_links[$n] = $final_link;
271  }
272  #now figure out which one points to the RSS file
273  for ($n = 0; $n < $link_count; $n++) {
274  if (strtolower($final_links[$n]['rel']) == 'alternate') {
275  if (strtolower($final_links[$n]['type']) == 'application/rss+xml') {
276  $href = $final_links[$n]['href'];
277  }
278  if (!$href and strtolower($final_links[$n]['type']) == 'text/xml') {
279  #kludge to make the first version of this still work
280  $href = $final_links[$n]['href'];
281  }
282  if ($href) {
283  if (strstr($href, "http://") !== false) { #if it's absolute
284  $full_url = $href;
285  } else { #otherwise, 'absolutize' it
286  $url_parts = parse_url($location);
287  #only made it work for http:// links. Any problem with this?
288  $full_url = "http://$url_parts[host]";
289  if (isset($url_parts['port'])) {
290  $full_url .= ":$url_parts[port]";
291  }
292  if ($href[0] != '/') { #it's a relative link on the domain
293  $full_url .= dirname($url_parts['path']);
294  if (substr($full_url, -1) != '/') {
295  #if the last character isn't a '/', add it
296  $full_url .= '/';
297  }
298  }
299  $full_url .= $href;
300  }
301  return $full_url;
302  }
303  }
304  }
305  return false;
306  }
307  }
$attributes
Definition: metadata.php:231
$location
Definition: buildRTE.php:44
$n
Definition: RandomTest.php:85
+ Here is the caller graph for this function:

◆ checkCacheHit()

ilExternalFeed::checkCacheHit ( )

Check cache hit.

Definition at line 164 of file class.ilExternalFeed.php.

References _createCacheDirectory(), getUrl(), MAGPIE_CACHE_AGE, and MAGPIE_OUTPUT_ENCODING.

165  {
167 
168  $cache = new RSSCache(MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE);
169 
170  $cache_status = 0; // response of check_cache
171  $request_headers = array(); // HTTP headers to send with fetch
172  $rss = 0; // parsed RSS object
173  $errormsg = 0; // errors, if any
174 
175  $cache_key = $this->getUrl() . MAGPIE_OUTPUT_ENCODING;
176 
177  if (!$cache->ERROR) {
178  // return cache HIT, MISS, or STALE
179  $cache_status = $cache->check_cache($cache_key);
180  }
181 
182  // if object cached, and cache is fresh, return cached obj
183  if ($cache_status == 'HIT') {
184  return true;
185  }
186 
187  return false;
188  }
const MAGPIE_OUTPUT_ENCODING(defined('ILIAS_DATA_DIR') &&defined('CLIENT_ID'))
const MAGPIE_CACHE_AGE
static _createCacheDirectory()
Create magpie cache directorry (if not existing)
+ Here is the call graph for this function:

◆ fetch()

ilExternalFeed::fetch ( )

Fetch the feed.

Definition at line 136 of file class.ilExternalFeed.php.

References getUrl(), and setError().

137  {
138  if ($this->getUrl() != "") {
139  $this->feed = @fetch_rss($this->getUrl());
140  }
141 
142  if (!$this->feed) {
143  $error = magpie_error();
144  if ($error == "") {
145  $this->setError("Unknown Error.");
146  } else {
147  $this->setError(magpie_error());
148  }
149  return false;
150  }
151 
152  if (is_array($this->feed->items)) {
153  foreach ($this->feed->items as $item) {
154  $item_obj = new ilExternalFeedItem();
155  $item_obj->setMagpieItem($item);
156  $this->items[] = $item_obj;
157  }
158  }
159  }
Wraps $item arrays from magpie.
setError($a_error)
Set Error.
+ Here is the call graph for this function:

◆ getChannelDescription()

ilExternalFeed::getChannelDescription ( )

Get Description.

Definition at line 201 of file class.ilExternalFeed.php.

202  {
203  return $this->feed->channel["description"];
204  }

◆ getChannelTitle()

ilExternalFeed::getChannelTitle ( )

Get Channel.

Definition at line 193 of file class.ilExternalFeed.php.

194  {
195  return $this->feed->channel["title"];
196  }

◆ getError()

ilExternalFeed::getError ( )

Get Error.

Returns
string Error

Definition at line 84 of file class.ilExternalFeed.php.

85  {
86  return $this->error;
87  }

◆ getItems()

ilExternalFeed::getItems ( )

Get Items.

Definition at line 209 of file class.ilExternalFeed.php.

References $items.

210  {
211  return $this->items;
212  }

◆ getUrl()

ilExternalFeed::getUrl ( )

Get Url.

Returns
string Url

Definition at line 64 of file class.ilExternalFeed.php.

References $url.

Referenced by checkCacheHit(), and fetch().

65  {
66  return $this->url;
67  }
$url
+ Here is the caller graph for this function:

◆ setError()

ilExternalFeed::setError (   $a_error)

Set Error.

Parameters
string$a_errorError

Definition at line 74 of file class.ilExternalFeed.php.

Referenced by fetch().

75  {
76  $this->error = $a_error;
77  }
+ Here is the caller graph for this function:

◆ setUrl()

ilExternalFeed::setUrl (   $a_url)

Set Url.

Parameters
string$a_urlUrl

Definition at line 54 of file class.ilExternalFeed.php.

55  {
56  $this->url = $a_url;
57  }

Field Documentation

◆ $items

ilExternalFeed::$items = array()
protected

Definition at line 29 of file class.ilExternalFeed.php.

Referenced by getItems().


The documentation for this class was generated from the following file: