root / derivative_projects / mediawiki_plugin / 1.0 / simplepie_mediawiki.php @ 960

1
<?php
2
/****************************************************
3
SIMPLEPIE PLUGIN FOR MEDIAWIKI
4
Add feeds to your MediaWiki installations.
5
6
Requires SimplePie 1.0 Beta 2 or newer.
7
8
Version: 1.0
9
Updated: 8 May 2006
10
Copyright: 2006 Ryan Parman, Geoffrey Sneddon
11
http://simplepie.org
12
13
*****************************************************
14
LICENSE:
15
16
GNU Lesser General Public License 2.1 (LGPL)
17
http://creativecommons.org/licenses/LGPL/2.1/
18
19
*****************************************************
20
Please submit all bug reports and feature requests to the SimplePie forums.
21
http://simplepie.org/support/
22
23
****************************************************/
24
25
if (isset($_GET['i']) && !empty($_GET['i'])) {
26
        require("./simplepie.inc");
27
        $feed = new SimplePie();
28
        $feed->bypass_image_hotlink();
29
        $feed->init();
30
}
31
else {
32
        require("./extensions/simplepie.inc");
33
        $wgExtensionFunctions[] = "SimplePieMW";
34
}
35
36
function SimplePieMW() {
37
        global $wgParser;
38
        $wgParser->setHook( "feed", "SimplePieMWCallback" );
39
}
40
41
function SimplePieMWCallback($input, $argv) {
42
        $feed = new SimplePie();
43
        $feed->feed_url($input);
44
        $feed->cache_location("./extensions/cache");
45
        $feed->bypass_image_hotlink();
46
        $feed->bypass_image_hotlink_page('./extensions/simplepie_mediawiki.php');
47
        $feed->init();
48
49
        $flink = $feed->get_feed_link();
50
        $ftitle = $feed->get_feed_title();
51
52
        $output='';
53
        $output .= '<div class="simplepie">';
54
        $output .= "<h3><a href=\"$flink\">$ftitle</a></h3>";
55
        $output .= '<ol>';
56
57
        $max = $feed->get_item_quantity();
58
        if (isset($argv['items']) && !empty($argv['items'])) $max = $feed->get_item_quantity($argv['items']);
59
60
        for($x=0; $x<$max; $x++) {
61
                $item = $feed->get_item($x);
62
                $link = $item->get_permalink();
63
                $title = StupefyEntities($item->get_title());
64
                $full_desc = StupefyEntities($item->get_description());
65
                $desc = $full_desc;
66
67
                if (isset($argv['shortdesc']) && !empty($argv['shortdesc'])) {
68
                        $suffix = '...';
69
                        $short_desc = trim(str_replace("\n", ' ', str_replace("\r", ' ', strip_tags(StupefyEntities($item->get_description())))));
70
                        $desc = substr($short_desc, 0, $argv['shortdesc']);
71
                        $lastchar = substr($desc, -1, 1);
72
                        if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
73
                        $desc .= $suffix;
74
                }
75
76
                if (isset($argv['showdesc']) && !empty($argv['showdesc']) && $argv['showdesc']==='false') {
77
                        if (isset($argv['showdate']) && !empty($argv['showdate'])) {
78
                                $output .= "<li><a href=\"$link\">$title</a> <span class=\"date\">" . $item->get_date($argv['showdate']) . "</span></li>";
79
                        } else {
80
                                $output .= "<li><a href=\"$link\">$title</a></li>";
81
                        }
82
                } else {
83
                        if (isset($argv['showdate']) && !empty($argv['showdate'])) {
84
                                $output .= "<li><strong><a href=\"$link\">$title</a> <span class=\"date\">" . $item->get_date($argv['showdate']) . "</span></strong><br />$desc</li>";
85
                        } else {
86
                                $output .= "<li><strong><a href=\"$link\">$title</a></strong><br />$desc</li>";
87
                        }
88
                }
89
        }
90
91
        $output .= '</ol>';
92
        $output .= '</div>';
93
94
        return $output;
95
}
96
97
// SmartyPants 1.5.1 changes rolled in May 2004 by Alex Rosenberg, http://monauraljerk.org/smartypants-php/
98
function StupefyEntities($s = '') {
99
        $inputs = array('&#8211;', '&#8212;', '&#8216;', '&#8217;', '&#8220;', '&#8221;', '&#8230;', '&#91;', '&#93;');
100
        $outputs = array('-', '--', "'", "'", '"', '"', '...', '[', ']');
101
        $s = str_replace($inputs, $outputs, $s);
102
        return $s;
103
}
104
105
?>
106