Handles external Feeds via Magpie libaray. More...
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() | |
Handles external Feeds via Magpie libaray.
Definition at line 40 of file class.ilExternalFeed.php.
| static ilExternalFeed::_checkUrl | ( | $ | a_url | ) | [static] |
Check Url.
| string | URL |
Definition at line 114 of file class.ilExternalFeed.php.
References _createCacheDirectory().
Referenced by ilFeedUrlInputGUI::checkInput().
{
if (!defined('IL_FEED_PROXY_HOST'))
{
ilExternalFeed::_createCacheDirectory();
$feed_set = new ilSetting("feed");
define('IL_FEED_PROXY_HOST', $feed_set->get("proxy"));
define('IL_FEED_PROXY_PORT', $feed_set->get("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 100 of file class.ilExternalFeed.php.
References ilUtil::getWebspaceDir(), and ilUtil::makeDir().
Referenced by _checkUrl(), checkCacheHit(), and ilExternalFeed().
{
if (!is_dir(ilUtil::getWebspaceDir()."/magpie_cache"))
{
ilUtil::makeDir(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.
| $a_url | URL that |
Definition at line 236 of file class.ilExternalFeed.php.
References $res, and _getRSSLocation().
Referenced by ilFeedUrlInputGUI::checkInput().
{
if (!defined('IL_FEED_PROXY_HOST'))
{
$feed_set = new ilSetting("feed");
define('IL_FEED_PROXY_HOST', $feed_set->get("proxy"));
define('IL_FEED_PROXY_PORT', $feed_set->get("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 266 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 180 of file class.ilExternalFeed.php.
References _createCacheDirectory(), and getUrl().
{
ilExternalFeed::_createCacheDirectory();
$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 145 of file class.ilExternalFeed.php.
References 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 218 of file class.ilExternalFeed.php.
{
return $this->feed->channel["description"];
}
| ilExternalFeed::getChannelTitle | ( | ) |
Get Channel.
Definition at line 210 of file class.ilExternalFeed.php.
{
return $this->feed->channel["title"];
}
| ilExternalFeed::getError | ( | ) |
Get Error.
Definition at line 92 of file class.ilExternalFeed.php.
{
return $this->error;
}
| ilExternalFeed::getItems | ( | ) |
| ilExternalFeed::getUrl | ( | ) |
Get Url.
Definition at line 72 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 47 of file class.ilExternalFeed.php.
References _createCacheDirectory().
{
// IF YOU ADD THINGS HERE, THEY MAY ALSO BE ADDED TO
// SOME OF THE STATIC METHODS
$this->_createCacheDirectory();
$feed_set = new ilSetting("feed");
define('IL_FEED_PROXY_HOST', $feed_set->get("proxy"));
define('IL_FEED_PROXY_PORT', $feed_set->get("proxy_port"));
}
Here is the call graph for this function:| ilExternalFeed::setError | ( | $ | a_error | ) |
Set Error.
| string | $a_error Error |
Definition at line 82 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.
| string | $a_url Url |
Definition at line 62 of file class.ilExternalFeed.php.
{
$this->url = $a_url;
}
ilExternalFeed::$items = array() [protected] |
Definition at line 42 of file class.ilExternalFeed.php.
1.7.1