function renderRss($input) { global $wgOutputEncoding; $DefaultEncoding = "ISO-8859-1"; $VersionNote = "Mediawiki rss extension by mutante, Duesentrieb, Rdb and Mafs"; $VersionLink = "http://meta.wikimedia.org/wiki/User:Mafs/RSS"; $VersionNo = "0.1"; $DisableCache = true; if (!$input) { return ""; } #if <rss>-section is empty, return nothing #parse fields in rss-section $fields = explode("|", $input); $url = @$fields[0]; $args = array(); for ($i = 1; $i < sizeof($fields); $i++) { $f = $fields[$i]; if (strpos($f, "=") === False) { $args[strtolower(trim($f))] = False; } else { list($k, $v) = explode("=", $f, 2); if (trim($v) == False) { $args[strtolower(trim($k))] = False; } else { $args[strtolower(trim($k))] = trim($v); } } } #get charset from argument-array $charset = @$args["charset"]; if (!$charset) { $charset = $DefaultEncoding; } #get max number of headlines from argument-array $maxheads = @$args["max"]; $headcnt = 0; #get short-flag from argument-array #if short is set, no description text is printed if (isset($args["short"])) { $short = True; } else { $short = False; } #get reverse-flag from argument-array if (isset($args["reverse"])) { $reverse = True; } else { $reverse = False; } #get version-flag from argument-array if (isset($args["version"])) { $DisplayVersion = True; } else { $DisplayVersion = False; } #get highlight terms from argument-array $rssHighlight = @$args["highlight"]; $rssHighlight = str_replace(" ", " ", $rssHighlight); $rssHighlight = explode(" ", trim($rssHighlight)); #get filter terms from argument-array $rssFilter = @$args["filter"]; $rssFilter = str_replace(" ", " ", $rssFilter); $rssFilter = explode(" ", trim($rssFilter)); #fetch rss. may be cached locally. #Refer to the documentation of magpie for details. $rss = @fetch_rss($url); #check for errors. if ($rss->ERROR) { return "<div>Failed to load RSS feed from {$url}: " . $rss->ERROR . "</div>"; #localize... } if (!is_array($rss->items)) { return "<div>Failed to load RSS feed from {$url}!</div>"; #localize... } #Bild title line $title = iconv($charset, $wgOutputEncoding, $rss->channel['title']); if (isset($rss->channel['link'])) { $title = "<a href='" . $rss->channel['link'] . "'>{$title}</a>"; } $output = "<h3>{$title}</h3>"; if ($reverse) { $rss->items = array_reverse($rss->items); } $description = False; foreach ($rss->items as $item) { if (isset($item['description'])) { $description = True; break; } } #Bild items if (!$short and $description) { #full item list $output .= "<dl>"; foreach ($rss->items as $item) { $d_text = true; $d_title = true; $href = trim(iconv($charset, $wgOutputEncoding, $item['link'])); $title = trim(iconv($charset, $wgOutputEncoding, $item['title'])); $d_title = wfRssFilter($title, $rssFilter); $title = wfRssHighlight($title, $rssHighlight); #bild description text if desired if ($item["description"]) { $text = trim(iconv($charset, $wgOutputEncoding, $item['description'])); #avoid pre-tags $text = str_replace("\r", " ", $text); $text = str_replace("\n", " ", $text); $text = str_replace("\t", " ", $text); $d_text = wfRssFilter($text, $rssFilter); $text = wfRssHighlight($text, $rssHighlight); $display = $d_text or $d_title; } else { $text = ""; $display = $d_title; } if ($display) { $output .= "<dt><a href='{$href}'>{$title}</a></dt>"; if ($text) { $output .= "<dd>{$text}</dd>\n"; } } #Cut off output when maxheads is reached: if (++$headcnt == $maxheads) { break; } } $output .= "</dl>"; } else { #short item list $output .= "<ul>"; foreach ($rss->items as $item) { $href = trim(iconv($charset, $wgOutputEncoding, $item['link'])); $title = trim(iconv($charset, $wgOutputEncoding, $item['title'])); $d_title = wfRssFilter($title, $rssFilter); $title = wfRssHighlight($title, $rssHighlight); if ($d_title) { $output .= "<li><a href='{$href}'>{$title}</a></li>"; } #Cut off output when maxheads is reached: if (++$headcnt == $maxheads) { break; } } $output .= "</ul>"; } if ($DisableCache) { global $wgVersion; # Do not cache this wiki page. # for details see http://public.kitware.com/Wiki/User:Barre/MediaWiki/Extensions global $wgTitle, $wgDBprefix; $ts = mktime(); $now = gmdate("YmdHis", $ts + 120); $ns = $wgTitle->getNamespace(); $ti = wfStrencode($wgTitle->getDBkey()); $version = preg_replace("/^([1-9]).([1-9]).*/", "\\1\\2", $wgVersion); if ($version > 14) { $sql = "UPDATE {$wgDBprefix}" . "page SET page_touched='{$now}' WHERE page_namespace={$ns} AND page_title='{$ti}'"; } else { $sql = "UPDATE {$wgDBprefix}" . "cur SET cur_touched='{$now}' WHERE cur_namespace={$ns} AND cur_title='{$ti}'"; } wfQuery($sql, DB_WRITE, ""); } $VersionText = ""; if ($VersionNote) { $VersionText = $VersionNote; } if ($VersionLink and $VersionNo) { $VersionText = $VersionText . " - <a href=\"{$VersionLink}\" title=\"{$VersionLink}\">version {$VersionNo}</a>."; } if (!$VersionLink and $VersionNo) { $VersionText = $VersionText . " - version {$VersionNo}."; } if ($DisplayVersion and $VersionText) { $output = $output . "<div style=\"background-color: #E0E0E0; font-weight: bold; font-size: 60%; padding: 0em 0.5em 0em 0.5em;\" >{$VersionText}</div>"; } return $output; }
function renderRss($input) { global $wgOutputEncoding, $wgParser; // Kill parser cache #$wgParser->disableCache(); global $wgParserCacheExpireTime; $wgParserCacheExpireTime = 600; wfDebug("soft disable Cache (rss)\n"); if (!$input) { return ''; } #if <rss>-section is empty, return nothing #Parse fields in rss-section $fields = explode("|", $input); $url = @$fields[0]; $args = array(); for ($i = 1; $i < sizeof($fields); $i++) { $f = $fields[$i]; if (strpos($f, "=") === false) { $args[strtolower(trim($f))] = false; } else { list($k, $v) = explode("=", $f, 2); if (trim($v) == false) { $args[strtolower(trim($k))] = false; } else { $args[strtolower(trim($k))] = trim($v); } } } #Get charset from argument-array $charset = @$args['charset']; if (!$charset) { $charset = $wgOutputEncoding; } #Get max number of headlines from argument-array $maxheads = @$args['max']; $headcnt = 0; #Get short-flag from argument-array #If short is set, no description text is printed if (isset($args['short'])) { $short = true; } else { $short = false; } #Get reverse-flag from argument-array if (isset($args['reverse'])) { $reverse = true; } else { $reverse = false; } # Get date format from argument-array if (isset($args["date"])) { $date = @$args["date"]; if ($date == '') { $date = wfMsg('rss-date-format'); } } else { $date = false; } #Get highlight terms from argument array $rssHighlight = @$args['highlight']; $rssHighlight = str_replace(' ', ' ', $rssHighlight); $rssHighlight = explode(' ', trim($rssHighlight)); #Get filter terms from argument-array $rssFilter = @$args['filter']; $rssFilter = str_replace(' ', ' ', $rssFilter); $rssFilter = explode(' ', trim($rssFilter)); #Filterout terms $rssFilterout = @$args['filterout']; $rssFilterout = str_replace(' ', ' ', $rssFilterout); $rssFilterout = explode(' ', trim($rssFilterout)); #Fetch RSS. May be cached locally. #Refer to the documentation of magpie for details. $rss = @fetch_rss($url); #Check for errors. if (empty($rss)) { return wfMsg('rss-empty', $url); } if ($rss->ERROR) { return wfMsg('rss-error', $url, $rss->ERROR); } if (!is_array($rss->items)) { return wfMsg('rss-empty', $url); } #Build title line #$title = iconv($charset, $wgOutputEncoding, $rss->channel['title']); #if( $rss->channel['link'] ) $title = "<a href='".$rss->channel['link']."'>$title</a>"; $output = ''; if ($reverse) { $rss->items = array_reverse($rss->items); } $description = false; foreach ($rss->items as $item) { if (isset($item['description']) && $item['description']) { $description = true; break; } } #Build items if (!$short and $description) { #full item list $output .= '<dl>'; foreach ($rss->items as $item) { $d_text = true; $d_title = true; $href = htmlspecialchars(trim(iconv($charset, $wgOutputEncoding, $item['link']))); $title = htmlspecialchars(trim(iconv($charset, $wgOutputEncoding, $item['title']))); if ($date) { $pubdate = trim(iconv($charset, $wgOutputEncoding, $item['pubdate'])); $pubdate = date($date, strtotime($pubdate)); } $d_title = wfRssFilter($title, $rssFilter); $d_title = wfRssFilterout($title, $rssFilterout); $title = wfRssHighlight($title, $rssHighlight); #Build description text if desired if ($item['description']) { $text = trim(iconv($charset, $wgOutputEncoding, $item['description'])); #Avoid pre-tags $text = str_replace("\r", ' ', $text); $text = str_replace("\n", ' ', $text); $text = str_replace("\t", ' ', $text); $text = str_replace('<br>', '', $text); $d_text = wfRssFilter($text, $rssFilter); $d_text = wfRssFilterout($text, $rssFilterout); $text = wfRssHighlight($text, $rssHighlight); $display = $d_text or $d_title; } else { $text = ''; $display = $d_title; } if ($display) { $output .= "<dt><a href='{$href}'><b>{$title}</b></a></dt>"; if ($date) { $output .= " ({$pubdate})"; } if ($text) { $output .= "<dd>{$text} <b>[<a href='{$href}'>?</a>]</b></dd>"; } } #Cut off output when maxheads is reached: if (++$headcnt == $maxheads) { break; } } $output .= '</dl>'; } else { #short item list ## HACKY HACKY HACKY $output .= '<ul>'; $displayed = array(); foreach ($rss->items as $item) { $href = htmlspecialchars(trim(iconv($charset, $wgOutputEncoding, $item['link']))); $title = htmlspecialchars(trim(iconv($charset, $wgOutputEncoding, $item['title']))); $d_title = wfRssFilter($title, $rssFilter) && wfRssFilterout($title, $rssFilterout); $title = wfRssHighlight($title, $rssHighlight); if ($date) { $pubdate = isset($item['pubdate']) ? trim(iconv($charset, $wgOutputEncoding, $item['pubdate'])) : ''; if ($pubdate == '') { $pubdate = isset($item['dc']) && is_array($item['dc']) && isset($item['dc']['date']) ? trim(iconv($charset, $wgOutputEncoding, $item['dc']['date'])) : ''; } $pubdate = date($date, strtotime($pubdate)); } if ($d_title && !in_array($title, $displayed)) { // Add date to ouput if specified $output .= '<li><a href="' . $href . '" title="' . $title . '">' . $title . '</a>'; if ($date) { $output .= " ({$pubdate})"; } $output .= '</li>'; $displayed[] = $title; #Cut off output when maxheads is reached: if (++$headcnt == $maxheads) { break; } } } $output .= '</ul>'; } return $output; }