| | 1 | <?php |
|---|
| | 2 | /** |
|---|
| | 3 | * A block to dislay an RSS feed. |
|---|
| | 4 | * |
|---|
| | 5 | * @package export |
|---|
| | 6 | * @author Demian Turner <demian@phpkitchen.com> |
|---|
| | 7 | * @author Werner M. Krauss <werner@seagullproject.org> |
|---|
| | 8 | */ |
|---|
| | 9 | |
|---|
| | 10 | class Export_Block_ShowRss |
|---|
| | 11 | { |
|---|
| | 12 | |
|---|
| | 13 | function init(&$output, $block_id, &$aParams) |
|---|
| | 14 | { |
|---|
| | 15 | SGL::logMessage(null, PEAR_LOG_DEBUG); |
|---|
| | 16 | |
|---|
| | 17 | return $this->getBlockContent($output, $block_id, $aParams); |
|---|
| | 18 | } |
|---|
| | 19 | |
|---|
| | 20 | function getBlockContent(&$output, $block_id, &$aParams) |
|---|
| | 21 | { |
|---|
| | 22 | if (ini_get('safe_mode') || !ini_get('allow_url_fopen')) { |
|---|
| | 23 | return 'Cannot request remote feed with safe_mode on or allow_url_fopen off'; |
|---|
| | 24 | } |
|---|
| | 25 | $c = &SGL_Config::singleton(); |
|---|
| | 26 | $conf = $c->getAll(); |
|---|
| | 27 | |
|---|
| | 28 | // set block params |
|---|
| | 29 | if (array_key_exists('rssSource', $aParams)) { |
|---|
| | 30 | $rssSource = $aParams['rssSource']; |
|---|
| | 31 | } else { |
|---|
| | 32 | return false; |
|---|
| | 33 | } |
|---|
| | 34 | |
|---|
| | 35 | $itemsToShow = (array_key_exists('itemsToShow', $aParams)) |
|---|
| | 36 | ? $aParams['itemsToShow'] |
|---|
| | 37 | : 5; |
|---|
| | 38 | |
|---|
| | 39 | |
|---|
| | 40 | $cache = & SGL_Cache::singleton($force = true); |
|---|
| | 41 | if ($data = $cache->get('sglSiteRss'.$block_id, 'blocks')) { |
|---|
| | 42 | $html = unserialize($data); |
|---|
| | 43 | SGL::logMessage('rss from cache', PEAR_LOG_DEBUG); |
|---|
| | 44 | } else { |
|---|
| | 45 | require_once "XML/RSS.php"; |
|---|
| | 46 | $rss =& new XML_RSS($rssSource); |
|---|
| | 47 | $rss->parse(); |
|---|
| | 48 | |
|---|
| | 49 | $html = "<ul class='noindent'>\n"; |
|---|
| | 50 | $x = 0; |
|---|
| | 51 | foreach ($rss->getItems() as $item) { |
|---|
| | 52 | $html .= "<li><a href=\"" . $item['link'] . "\">" . $item['title'] . "</a></li>\n"; |
|---|
| | 53 | $x ++; |
|---|
| | 54 | if ($x >= $itemsToShow) { |
|---|
| | 55 | break; |
|---|
| | 56 | } |
|---|
| | 57 | } |
|---|
| | 58 | $html .= "</ul>\n"; |
|---|
| | 59 | $cache->save(serialize($html), 'sglSiteRss'.$block_id, 'blocks'); |
|---|
| | 60 | SGL::logMessage('rss from remote', PEAR_LOG_DEBUG); |
|---|
| | 61 | } |
|---|
| | 62 | return $html; |
|---|
| | 63 | } |
|---|
| | 64 | } |
|---|
| | 65 | ?> |