ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 23 of file class.ilExternalFeed.php.

Constructor & Destructor Documentation

◆ __construct()

ilExternalFeed::__construct ( )

Constructor.

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

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

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

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

102 {
103 if (!defined('IL_FEED_PROXY_HOST')) {
105
106 if (ilProxySettings::_getInstance()->isActive()) {
107 define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
108 define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
109 } else {
110 define('IL_FEED_PROXY_HOST', "");
111 define('IL_FEED_PROXY_PORT', "");
112 }
113 }
114
115 $feed = @fetch_rss($a_url);
116 if (!$feed) {
117 $error = magpie_error();
118
119 if ($error != "") {
120 return $error;
121 } else {
122 return "Unknown Error.";
123 }
124 }
125
126 return true;
127 }
$error
Definition: Error.php:17
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27

References $error, _createCacheDirectory(), ilProxySettings\_getInstance(), and defined.

Referenced by ilFeedUrlInputGUI\checkInput().

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

89 {
90 if (!is_dir(ilUtil::getDataDir() . "/magpie_cache")) {
91 ilUtil::makeDir(ilUtil::getDataDir() . "/magpie_cache");
92 }
93 }
static getDataDir()
get data directory (outside webspace)
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...

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

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

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

216 {
217 if (!defined('IL_FEED_PROXY_HOST')) {
218 if (ilProxySettings::_getInstance()->isActive()) {
219 define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost());
220 define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort());
221 } else {
222 define('IL_FEED_PROXY_HOST', "");
223 define('IL_FEED_PROXY_PORT', "");
224 }
225 }
226
227 $res = @fopen($a_url, "r");
228
229 if (!$res) {
230 return "";
231 }
232
233 $contents = '';
234 while (!feof($res)) {
235 $contents.= fread($res, 8192);
236 }
237 fclose($res);
238
240 }
static _getRSSLocation($html, $location)
This one is by Keith Devens , see http://keithdevens.com/weblog/archive/2002/Jun/03/RSSAuto-Discovery...
foreach($_POST as $key=> $value) $res

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

Referenced by ilFeedUrlInputGUI\checkInput().

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

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

References $attributes, $html, $links, $location, and $n.

Referenced by _determineFeedUrl().

+ Here is the caller graph for this function:

◆ checkCacheHit()

ilExternalFeed::checkCacheHit ( )

Check cache hit.

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

161 {
163
164 $cache = new RSSCache(MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE);
165
166 $cache_status = 0; // response of check_cache
167 $request_headers = array(); // HTTP headers to send with fetch
168 $rss = 0; // parsed RSS object
169 $errormsg = 0; // errors, if any
170
171 $cache_key = $this->getUrl() . MAGPIE_OUTPUT_ENCODING;
172
173 if (!$cache->ERROR) {
174 // return cache HIT, MISS, or STALE
175 $cache_status = $cache->check_cache($cache_key);
176 }
177
178 // if object cached, and cache is fresh, return cached obj
179 if ($cache_status == 'HIT') {
180 return true;
181 }
182
183 return false;
184 }
const MAGPIE_CACHE_AGE
const MAGPIE_CACHE_DIR
const MAGPIE_OUTPUT_ENCODING

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

+ Here is the call graph for this function:

◆ fetch()

ilExternalFeed::fetch ( )

Fetch the feed.

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

133 {
134 if ($this->getUrl() != "") {
135 $this->feed = @fetch_rss($this->getUrl());
136 }
137
138 if (!$this->feed) {
139 $error = magpie_error();
140 if ($error == "") {
141 $this->setError("Unknown Error.");
142 } else {
143 $this->setError(magpie_error());
144 }
145 return false;
146 }
147
148 if (is_array($this->feed->items)) {
149 foreach ($this->feed->items as $item) {
150 $item_obj = new ilExternalFeedItem();
151 $item_obj->setMagpieItem($item);
152 $this->items[] = $item_obj;
153 }
154 }
155 }
Wraps $item arrays from magpie.
setError($a_error)
Set Error.

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

+ Here is the call graph for this function:

◆ getChannelDescription()

ilExternalFeed::getChannelDescription ( )

Get Description.

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

198 {
199 return $this->feed->channel["description"];
200 }

◆ getChannelTitle()

ilExternalFeed::getChannelTitle ( )

Get Channel.

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

190 {
191 return $this->feed->channel["title"];
192 }

◆ getError()

ilExternalFeed::getError ( )

Get Error.

Returns
string Error

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

81 {
82 return $this->error;
83 }

References $error.

◆ getItems()

ilExternalFeed::getItems ( )

Get Items.

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

206 {
207 return $this->items;
208 }

References $items.

◆ getUrl()

ilExternalFeed::getUrl ( )

Get Url.

Returns
string Url

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

61 {
62 return $this->url;
63 }
$url

References $url.

Referenced by checkCacheHit(), and fetch().

+ Here is the caller graph for this function:

◆ setError()

ilExternalFeed::setError (   $a_error)

Set Error.

Parameters
string$a_errorError

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

71 {
72 $this->error = $a_error;
73 }
error($a_errmsg)
set error message @access public

References error().

Referenced by fetch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUrl()

ilExternalFeed::setUrl (   $a_url)

Set Url.

Parameters
string$a_urlUrl

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

51 {
52 $this->url = $a_url;
53 }

Field Documentation

◆ $items

ilExternalFeed::$items = array()
protected

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

Referenced by getItems().


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