4 require_once
'classes/class.ilProxySettings.php';
6 define(
"MAGPIE_DIR",
"./Services/Feeds/magpierss/");
7 define(
"MAGPIE_CACHE_ON",
true);
8 define(
"MAGPIE_CACHE_DIR",
"./".
ILIAS_WEB_DIR.
"/".CLIENT_ID.
"/magpie_cache");
9 define(
'MAGPIE_OUTPUT_ENCODING',
"UTF-8");
10 define(
'MAGPIE_CACHE_AGE', 900);
13 include_once(
"./Services/Feeds/classes/class.ilExternalFeedItem.php");
42 define(
'IL_FEED_PROXY_HOST',
"");
43 define(
'IL_FEED_PROXY_PORT',
"");
74 $this->error = $a_error;
106 if (!defined(
'IL_FEED_PROXY_HOST'))
117 define(
'IL_FEED_PROXY_HOST',
"");
118 define(
'IL_FEED_PROXY_PORT',
"");
122 $feed = @fetch_rss($a_url);
133 return "Unknown Error.";
145 if ($this->
getUrl() !=
"")
147 $this->feed = @fetch_rss($this->
getUrl());
164 if (is_array($this->feed->items))
166 foreach($this->feed->items as $item)
169 $item_obj->setMagpieItem($item);
170 $this->items[] = $item_obj;
185 $request_headers = array();
189 $cache_key = $this->
getUrl().MAGPIE_OUTPUT_ENCODING;
191 if (!$cache->ERROR) {
193 $cache_status = $cache->check_cache( $cache_key);
197 if ($cache_status ==
'HIT')
210 return $this->feed->channel[
"title"];
218 return $this->feed->channel[
"description"];
236 if (!defined(
'IL_FEED_PROXY_HOST'))
245 define(
'IL_FEED_PROXY_HOST',
"");
246 define(
'IL_FEED_PROXY_PORT',
"");
250 $res = @fopen($a_url,
"r");
260 $contents.= fread(
$res, 8192);
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);
287 $att[1] = preg_replace(
'/([\'"]?)(.*)\1/',
'$2', $att[1]);
288 $final_link[strtolower($att[0])] = $att[1];
291 $final_links[$n] = $final_link;
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'];
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'];
304 if(strstr($href,
"http://") !==
false){ #
if it
's absolute
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]";
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