root / derivative_projects / mediawiki_plugin / 1.2 / 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.2
9
Updated: 19 June 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
        $success = $feed->init();
48
49
        if ($success && $feed->data) {
50
                $flink = $feed->get_feed_link();
51
                $ftitle = $feed->get_feed_title();
52
53
                $output='';
54
                $output .= '<div class="simplepie">';
55
                if (!isset($argv['showtitle']) || empty($argv['showtitle']) || $argv['showtitle'] == "true") {
56
                        if (isset($argv['alttitle']) && !empty($argv['alttitle'])) {
57
                                if ($ftitle != '' && $flink != '') $output .= "<h3><a href=\"$flink\">" . $argv['alttitle'] . "</a></h3>";
58
                                else if ($ftitle != '') $output .= "<h3>" . $argv['alttitle'] . "</h3>";
59
                        }
60
                        else {
61
                                if ($ftitle != '' && $flink != '') $output .= "<h3><a href=\"$flink\">$ftitle</a></h3>";
62
                                else if ($ftitle != '') $output .= "<h3>$ftitle</h3>";
63
                        }
64
                }
65
                $output .= '<ol>';
66
67
                $max = $feed->get_item_quantity();
68
                if (isset($argv['items']) && !empty($argv['items'])) $max = $feed->get_item_quantity($argv['items']);
69
70
                for($x=0; $x<$max; $x++) {
71
                        $item = $feed->get_item($x);
72
                        $link = $item->get_permalink();
73
                        $title = StupefyEntities($item->get_title());
74
                        $full_desc = StupefyEntities($item->get_description());
75
                        $desc = $full_desc;
76
77
                        if (isset($argv['shortdesc']) && !empty($argv['shortdesc'])) {
78
                                $suffix = '...';
79
                                $short_desc = trim(str_replace("\n", ' ', str_replace("\r", ' ', strip_tags(StupefyEntities($item->get_description())))));
80
                                $desc = substr($short_desc, 0, $argv['shortdesc']);
81
                                $lastchar = substr($desc, -1, 1);
82
                                if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
83
                                $desc .= $suffix;
84
                        }
85
86
                        if (isset($argv['showdesc']) && !empty($argv['showdesc']) && $argv['showdesc']==='false') {
87
                                if (isset($argv['showdate']) && !empty($argv['showdate'])) {
88
                                        $output .= "<li><a href=\"$link\">$title</a> <span class=\"date\">" . $item->get_date($argv['showdate']) . "</span></li>";
89
                                } else {
90
                                        $output .= "<li><a href=\"$link\">$title</a></li>";
91
                                }
92
                        } else {
93
                                if (isset($argv['showdate']) && !empty($argv['showdate'])) {
94
                                        $output .= "<li><strong><a href=\"$link\">$title</a> <span class=\"date\">" . $item->get_date($argv['showdate']) . "</span></strong><br />$desc</li>";
95
                                } else {
96
                                        $output .= "<li><strong><a href=\"$link\">$title</a></strong><br />$desc</li>";
97
                                }
98
                        }
99
                }
100
101
                $output .= '</ol>';
102
                $output .= '</div>';
103
        }
104
        else {
105
                if (isset($argv['error']) && !empty($argv['error'])) $output = $argv['error'];
106
                else if (isset($feed->error)) $output = $feed->error;
107
        }
108
109
        return $output;
110
}
111
112
// SmartyPants 1.5.1 changes rolled in May 2004 by Alex Rosenberg, http://monauraljerk.org/smartypants-php/
113
function StupefyEntities($s = '') {
114
        $inputs = array('&#8211;', '&#8212;', '&#8216;', '&#8217;', '&#8220;', '&#8221;', '&#8230;', '&#91;', '&#93;');
115
        $outputs = array('-', '--', "'", "'", '"', '"', '...', '[', ']');
116
        $s = str_replace($inputs, $outputs, $s);
117
        return $s;
118
}
119
120
?>
121