ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilExternalFeed Class Reference

Handles external Feeds via Magpie libaray. More...

+ Collaboration diagram for ilExternalFeed:

Public Member Functions

 ilExternalFeed ()
 Constructor.
 setUrl ($a_url)
 Set Url.
 getUrl ()
 Get Url.
 setError ($a_error)
 Set Error.
 getError ()
 Get Error.
 fetch ()
 Fetch the feed.
 checkCacheHit ()
 Check cache hit.
 getChannelTitle ()
 Get Channel.
 getChannelDescription ()
 Get Description.
 getItems ()
 Get Items.
 _getRSSLocation ($html, $location)
 This one is by Keith Devens , see http://keithdevens.com/weblog/archive/2002/Jun/03/RSSAuto-DiscoveryPHP.

Static Public Member Functions

static _createCacheDirectory ()
 Create magpie cache directorry (if not existing)
static _checkUrl ($a_url)
 Check Url.
static _determineFeedUrl ($a_url)
 Determine Feed Url.

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

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 $error, _createCacheDirectory(), and ilProxySettings\_getInstance().

Referenced by ilFeedUrlInputGUI\checkInput().

{
if (!defined('IL_FEED_PROXY_HOST'))
{
{
define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
}
else
{
define('IL_FEED_PROXY_HOST', "");
define('IL_FEED_PROXY_PORT', "");
}
}
$feed = @fetch_rss($a_url);
if (!$feed)
{
$error = magpie_error();
if ($error != "")
{
return $error;
}
else
{
return "Unknown Error.";
}
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

{
if (!is_dir(ilUtil::getWebspaceDir()."/magpie_cache"))
{
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

{
if (!defined('IL_FEED_PROXY_HOST'))
{
{
define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
}
else
{
define('IL_FEED_PROXY_HOST', "");
define('IL_FEED_PROXY_PORT', "");
}
}
$res = @fopen($a_url, "r");
if (!$res)
{
return "";
}
$contents = '';
while (!feof($res))
{
$contents.= fread($res, 8192);
}
fclose($res);
return ilExternalFeed::_getRSSLocation($contents, $a_url);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

Referenced by _determineFeedUrl().

{
if(!$html or !$location){
return false;
}else{
#search through the HTML, save all <link> tags
# and store each link's attributes in an associative array
preg_match_all('/<link\s+(.*?)\s*\/?>/si', $html, $matches);
$links = $matches[1];
$final_links = array();
$link_count = count($links);
for($n=0; $n<$link_count; $n++){
$attributes = preg_split('/\s+/s', $links[$n]);
foreach($attributes as $attribute){
$att = preg_split('/\s*=\s*/s', $attribute, 2);
if(isset($att[1])){
$att[1] = preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]);
$final_link[strtolower($att[0])] = $att[1];
}
}
$final_links[$n] = $final_link;
}
#now figure out which one points to the RSS file
for($n=0; $n<$link_count; $n++){
if(strtolower($final_links[$n]['rel']) == 'alternate'){
if(strtolower($final_links[$n]['type']) == 'application/rss+xml'){
$href = $final_links[$n]['href'];
}
if(!$href and strtolower($final_links[$n]['type']) == 'text/xml'){
#kludge to make the first version of this still work
$href = $final_links[$n]['href'];
}
if($href){
if(strstr($href, "http://") !== false){ #if it's absolute
$full_url = $href;
}else{ #otherwise, 'absolutize' it
$url_parts = parse_url($location);
#only made it work for http:// links. Any problem with this?
$full_url = "http://$url_parts[host]";
if(isset($url_parts['port'])){
$full_url .= ":$url_parts[port]";
}
if($href{0} != '/'){ #it's a relative link on the domain
$full_url .= dirname($url_parts['path']);
if(substr($full_url, -1) != '/'){
#if the last character isn't a '/', add it
$full_url .= '/';
}
}
$full_url .= $href;
}
return $full_url;
}
}
}
return false;
}
}

+ Here is the caller graph for this function:

ilExternalFeed::checkCacheHit ( )

Check cache hit.

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

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

{
$cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );
$cache_status = 0; // response of check_cache
$request_headers = array(); // HTTP headers to send with fetch
$rss = 0; // parsed RSS object
$errormsg = 0; // errors, if any
$cache_key = $this->getUrl().MAGPIE_OUTPUT_ENCODING;
if (!$cache->ERROR) {
// return cache HIT, MISS, or STALE
$cache_status = $cache->check_cache( $cache_key);
}
// if object cached, and cache is fresh, return cached obj
if ($cache_status == 'HIT')
{
return true;
}
return false;
}

+ Here is the call graph for this function:

ilExternalFeed::fetch ( )

Fetch the feed.

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

References $error, getUrl(), and setError().

{
if ($this->getUrl() != "")
{
$this->feed = @fetch_rss($this->getUrl());
}
if(!$this->feed)
{
$error = magpie_error();
if ($error == "")
{
$this->setError("Unknown Error.");
}
else
{
$this->setError(magpie_error());
}
return false;
}
if (is_array($this->feed->items))
{
foreach($this->feed->items as $item)
{
$item_obj = new ilExternalFeedItem();
$item_obj->setMagpieItem($item);
$this->items[] = $item_obj;
}
}
}

+ Here is the call graph for this function:

ilExternalFeed::getChannelDescription ( )

Get Description.

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

{
return $this->feed->channel["description"];
}
ilExternalFeed::getChannelTitle ( )

Get Channel.

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

{
return $this->feed->channel["title"];
}
ilExternalFeed::getError ( )

Get Error.

Returns
string Error

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

References $error.

{
return $this->error;
}
ilExternalFeed::getItems ( )

Get Items.

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

References $items.

{
return $this->items;
}
ilExternalFeed::getUrl ( )

Get Url.

Returns
string Url

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

Referenced by checkCacheHit(), and fetch().

{
return $this->url;
}

+ Here is the caller graph for this function:

ilExternalFeed::ilExternalFeed ( )

Constructor.

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

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

{
// IF YOU ADD THINGS HERE, THEY MAY ALSO BE ADDED TO
// SOME OF THE STATIC METHODS
{
define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
}
else
{
define('IL_FEED_PROXY_HOST', "");
define('IL_FEED_PROXY_PORT', "");
}
}

+ Here is the call graph for this function:

ilExternalFeed::setError (   $a_error)

Set Error.

Parameters
string$a_errorError

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

Referenced by fetch().

{
$this->error = $a_error;
}

+ Here is the caller graph for this function:

ilExternalFeed::setUrl (   $a_url)

Set Url.

Parameters
string$a_urlUrl

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

{
$this->url = $a_url;
}

Field Documentation

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: