840f45fe511ab29b367be226c405d6042ef898c4
[atutor.git] / mods / wiki / plugins / mpi / mpi_syndicate.php
1 <?php
2 /*
3    Allows to embed a RSS feed into a page. It retrieves and decodes the
4    external URL and caches results in the database for later reuse.
5
6    <?plugin Syndicate url="http://example.com/rss.php" limit=10 ?>
7    
8    @depends: http, http_cache, xml, feed, feedparse
9 */
10
11
12 $ewiki_plugins["mpi"]["syndicate"] = "ewiki_mpi_syndicate";
13
14 function ewiki_mpi_syndicate($action, &$args, &$iii, &$s) {
15    global $ewiki_id;
16
17    #-- params
18    ($url = $args["url"]) or ($args = $args["_"]);
19    ($cut = $args["limit"]) or ($cut = $args["cut"]) or ($cut = 10);
20
21    #-- fetch
22    list($channel, $item) = ewiki_feed_get($url);
23
24    #-- insert as html into current page
25    if ($channel) {
26       $o = "<b><a href=\"".htmlentities($channel[link])."\">".htmlentities($channel[title]) . "</a></b><br />\n";
27       $item = array_slice($item, 0, $cut);
28       foreach ($item as $dat) {
29          $dat = array_map("htmlentities", $dat);
30          $o .= "<a href=\"$dat[link]\">$dat[title]</a> $dat[description] <br />\n";
31       }
32       return($o);
33    }
34 }
35
36
37 ?>