ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
ilExternalFeed Class Reference

Handles external Feeds via Magpie libaray. More...

+ Collaboration diagram for ilExternalFeed:

Public Member Functions

 ilExternalFeed ()
 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...
 
 _getRSSLocation ($html, $location)
 This one is by Keith Devens , see http://keithdevens.com/weblog/archive/2002/Jun/03/RSSAuto-DiscoveryPHP. 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...
 

Protected Attributes

 $items = array()
 

Detailed Description

Handles external Feeds via Magpie libaray.

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

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

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 104 of file class.ilExternalFeed.php.

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

Referenced by ilFeedUrlInputGUI\checkInput().

105  {
106  if (!defined('IL_FEED_PROXY_HOST'))
107  {
109 
110  if(ilProxySettings::_getInstance()->isActive())
111  {
112  define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
113  define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
114  }
115  else
116  {
117  define('IL_FEED_PROXY_HOST', "");
118  define('IL_FEED_PROXY_PORT', "");
119  }
120  }
121 
122  $feed = @fetch_rss($a_url);
123  if (!$feed)
124  {
125  $error = magpie_error();
126 
127  if ($error != "")
128  {
129  return $error;
130  }
131  else
132  {
133  return "Unknown Error.";
134  }
135  }
136 
137  return true;
138  }
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 90 of file class.ilExternalFeed.php.

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

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

91  {
92  if (!is_dir(ilUtil::getWebspaceDir()."/magpie_cache"))
93  {
94  ilUtil::makeDir(ilUtil::getWebspaceDir()."/magpie_cache");
95  }
96  }
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getWebspaceDir($mode="filesystem")
get webspace directory
+ 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 234 of file class.ilExternalFeed.php.

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

Referenced by ilFeedUrlInputGUI\checkInput().

235  {
236  if (!defined('IL_FEED_PROXY_HOST'))
237  {
238  if(ilProxySettings::_getInstance()->isActive())
239  {
240  define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
241  define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
242  }
243  else
244  {
245  define('IL_FEED_PROXY_HOST', "");
246  define('IL_FEED_PROXY_PORT', "");
247  }
248  }
249 
250  $res = @fopen($a_url, "r");
251 
252  if (!$res)
253  {
254  return "";
255  }
256 
257  $contents = '';
258  while (!feof($res))
259  {
260  $contents.= fread($res, 8192);
261  }
262  fclose($res);
263 
264  return ilExternalFeed::_getRSSLocation($contents, $a_url);
265  }
_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()

ilExternalFeed::_getRSSLocation (   $html,
  $location 
)

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

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

References $location, and $n.

Referenced by _determineFeedUrl().

272  {
273  if(!$html or !$location){
274  return false;
275  }else{
276  #search through the HTML, save all <link> tags
277  # and store each link's attributes in an associative array
278  preg_match_all('/<link\s+(.*?)\s*\/?>/si', $html, $matches);
279  $links = $matches[1];
280  $final_links = array();
281  $link_count = count($links);
282  for($n=0; $n<$link_count; $n++){
283  $attributes = preg_split('/\s+/s', $links[$n]);
284  foreach($attributes as $attribute){
285  $att = preg_split('/\s*=\s*/s', $attribute, 2);
286  if(isset($att[1])){
287  $att[1] = preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]);
288  $final_link[strtolower($att[0])] = $att[1];
289  }
290  }
291  $final_links[$n] = $final_link;
292  }
293  #now figure out which one points to the RSS file
294  for($n=0; $n<$link_count; $n++){
295  if(strtolower($final_links[$n]['rel']) == 'alternate'){
296  if(strtolower($final_links[$n]['type']) == 'application/rss+xml'){
297  $href = $final_links[$n]['href'];
298  }
299  if(!$href and strtolower($final_links[$n]['type']) == 'text/xml'){
300  #kludge to make the first version of this still work
301  $href = $final_links[$n]['href'];
302  }
303  if($href){
304  if(strstr($href, "http://") !== false){ #if it's absolute
305  $full_url = $href;
306  }else{ #otherwise, 'absolutize' it
307  $url_parts = parse_url($location);
308  #only made it work for http:// links. Any problem with this?
309  $full_url = "http://$url_parts[host]";
310  if(isset($url_parts['port'])){
311  $full_url .= ":$url_parts[port]";
312  }
313  if($href{0} != '/'){ #it's a relative link on the domain
314  $full_url .= dirname($url_parts['path']);
315  if(substr($full_url, -1) != '/'){
316  #if the last character isn't a '/', add it
317  $full_url .= '/';
318  }
319  }
320  $full_url .= $href;
321  }
322  return $full_url;
323  }
324  }
325  }
326  return false;
327  }
328  }
$location
Definition: buildRTE.php:44
$n
Definition: RandomTest.php:80
+ Here is the caller graph for this function:

◆ checkCacheHit()

ilExternalFeed::checkCacheHit ( )

Check cache hit.

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

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

179  {
181 
182  $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );
183 
184  $cache_status = 0; // response of check_cache
185  $request_headers = array(); // HTTP headers to send with fetch
186  $rss = 0; // parsed RSS object
187  $errormsg = 0; // errors, if any
188 
189  $cache_key = $this->getUrl().MAGPIE_OUTPUT_ENCODING;
190 
191  if (!$cache->ERROR) {
192  // return cache HIT, MISS, or STALE
193  $cache_status = $cache->check_cache( $cache_key);
194  }
195 
196  // if object cached, and cache is fresh, return cached obj
197  if ($cache_status == 'HIT')
198  {
199  return true;
200  }
201 
202  return false;
203  }
const MAGPIE_CACHE_AGE
static _createCacheDirectory()
Create magpie cache directorry (if not existing)
const MAGPIE_CACHE_DIR
+ Here is the call graph for this function:

◆ fetch()

ilExternalFeed::fetch ( )

Fetch the feed.

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

References getUrl(), and setError().

144  {
145  if ($this->getUrl() != "")
146  {
147  $this->feed = @fetch_rss($this->getUrl());
148  }
149 
150  if(!$this->feed)
151  {
152  $error = magpie_error();
153  if ($error == "")
154  {
155  $this->setError("Unknown Error.");
156  }
157  else
158  {
159  $this->setError(magpie_error());
160  }
161  return false;
162  }
163 
164  if (is_array($this->feed->items))
165  {
166  foreach($this->feed->items as $item)
167  {
168  $item_obj = new ilExternalFeedItem();
169  $item_obj->setMagpieItem($item);
170  $this->items[] = $item_obj;
171  }
172  }
173  }
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 216 of file class.ilExternalFeed.php.

217  {
218  return $this->feed->channel["description"];
219  }

◆ getChannelTitle()

ilExternalFeed::getChannelTitle ( )

Get Channel.

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

209  {
210  return $this->feed->channel["title"];
211  }

◆ getError()

ilExternalFeed::getError ( )

Get Error.

Returns
string Error

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

83  {
84  return $this->error;
85  }

◆ getItems()

ilExternalFeed::getItems ( )

Get Items.

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

References $items.

225  {
226  return $this->items;
227  }

◆ getUrl()

ilExternalFeed::getUrl ( )

Get Url.

Returns
string Url

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

Referenced by checkCacheHit(), and fetch().

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

◆ ilExternalFeed()

ilExternalFeed::ilExternalFeed ( )

Constructor.

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

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

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

◆ setError()

ilExternalFeed::setError (   $a_error)

Set Error.

Parameters
string$a_errorError

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

Referenced by fetch().

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

◆ setUrl()

ilExternalFeed::setUrl (   $a_url)

Set Url.

Parameters
string$a_urlUrl

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

53  {
54  $this->url = $a_url;
55  }

Field Documentation

◆ $items

ilExternalFeed::$items = array()
protected

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

Referenced by getItems().


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