Projet

Général

Profil

Télécharger (6,04 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / widgets / widgets / rss.widget.php @ 6f3d2063

1
<?php
2
/*
3
        $Id$
4
        Copyright 2009 Scott Ullrich
5
        Part of pfSense widgets (https://www.pfsense.org)
6

    
7
        Redistribution and use in source and binary forms, with or without
8
        modification, are permitted provided that the following conditions are met:
9

    
10
        1. Redistributions of source code must retain the above copyright notice,
11
           this list of conditions and the following disclaimer.
12

    
13
        2. Redistributions in binary form must reproduce the above copyright
14
           notice, this list of conditions and the following disclaimer in the
15
           documentation and/or other materials provided with the distribution.
16

    
17
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
        POSSIBILITY OF SUCH DAMAGE.
27
*/
28

    
29
$nocsrf = true;
30

    
31
require_once("guiconfig.inc");
32
require_once("pfsense-utils.inc");
33
require_once("functions.inc");
34

    
35
if($_POST['rssfeed']) {
36
	$config['widgets']['rssfeed'] = str_replace("\n", ",", $_POST['rssfeed']);
37
	$config['widgets']['rssmaxitems'] = str_replace("\n", ",", $_POST['rssmaxitems']);
38
	$config['widgets']['rsswidgetheight'] = $_POST['rsswidgetheight'];
39
	$config['widgets']['rsswidgettextlength'] = $_POST['rsswidgettextlength'];
40
	write_config("Saved RSS Widget feed via Dashboard");
41
	header("Location: /");
42
}
43

    
44
// Use saved feed and max items
45
if($config['widgets']['rssfeed'])
46
	$rss_feed_s = explode(",", $config['widgets']['rssfeed']);
47

    
48
if($config['widgets']['rssmaxitems'])
49
	$max_items =  $config['widgets']['rssmaxitems'];
50

    
51
if($config['widgets']['rsswidgetheight'])
52
	$rsswidgetheight =  $config['widgets']['rsswidgetheight'];
53

    
54
if($config['widgets']['rsswidgettextlength'])
55
	$rsswidgettextlength =  $config['widgets']['rsswidgettextlength'];
56

    
57
// Set a default feed if none exists
58
if(!$rss_feed_s) {
59
	$rss_feed_s = "https://blog.pfsense.org";
60
	$config['widgets']['rssfeed'] = "https://blog.pfsense.org";
61
}
62

    
63
if(!$max_items)
64
	$max_items = 10;
65

    
66
if(!$rsswidgetheight)
67
	$rsswidgetheight = 300;
68

    
69
if(!$rsswidgettextlength)
70
	$rsswidgettextlength = 140;	// oh twitter, how do we love thee?
71

    
72
if($config['widgets']['rssfeed'])
73
	$textarea_txt =  str_replace(",", "\n", $config['widgets']['rssfeed']);
74
else
75
	$textarea_txt = "";
76

    
77
?>
78

    
79
<input type="hidden" id="rss-config" name="rss-config" value="" />
80

    
81
<div id="rss-settings" class="widgetconfigdiv" style="display:none;">
82
	<form action="/widgets/widgets/rss.widget.php" method="post" name="iformc">
83
		<textarea name="rssfeed" class="formfld unknown textarea_widget" id="rssfeed" cols="40" rows="3"><?=$textarea_txt;?></textarea>
84
		<br />
85
		<table summary="rss widget">
86
			<tr>
87
				<td align="right">
88
					Display number of items:
89
				</td>
90
				<td>
91
					<select name='rssmaxitems' id='rssmaxitems'>
92
						<option value='<?= $max_items ?>'><?= $max_items ?></option>
93
						<?php
94
							for($x=100; $x<5100; $x=$x+100)
95
								echo "<option value='{$x}'>{$x}</option>\n";
96
						?>
97
					</select>
98
				</td>
99
			</tr>
100
			<tr>
101
				<td align="right">
102
					Widget height:
103
				</td>
104
				<td>
105
					<select name='rsswidgetheight' id='rsswidgetheight'>
106
						<option value='<?= $rsswidgetheight ?>'><?= $rsswidgetheight ?>px</option>
107
						<?php
108
							for($x=100; $x<5100; $x=$x+100)
109
								echo "<option value='{$x}'>{$x}px</option>\n";
110
						?>
111
					</select>
112
				</td>
113
			</tr>
114
			<tr>
115
				<td align="right">
116
					Show how many characters from story:
117
				</td>
118
				<td>
119
					<select name='rsswidgettextlength' id='rsswidgettextlength'>
120
						<option value='<?= $rsswidgettextlength ?>'><?= $rsswidgettextlength ?></option>
121
						<?php
122
							for($x=10; $x<5100; $x=$x+10)
123
								echo "<option value='{$x}'>{$x}</option>\n";
124
						?>
125
					</select>
126
				</td>
127
			</tr>
128
			<tr>
129
				<td>
130
					&nbsp;
131
				</td>
132
				<td>
133
					<input id="submitc" name="submitc" type="submit" class="formbtn" value="Save" />
134
				</td>
135
			</tr>
136
		</table>
137
	</form>
138
</div>
139

    
140
<div id="rss-widgets" style="padding: 5px; height: <?=$rsswidgetheight?>px; overflow:scroll;">
141
<?php
142
	if(!is_dir("/tmp/simplepie")) {
143
		mkdir("/tmp/simplepie");
144
		mkdir("/tmp/simplepie/cache");
145
	}
146
	exec("chmod a+rw /tmp/simplepie/.");
147
	exec("chmod a+rw /tmp/simplepie/cache/.");
148
	require_once("simplepie/simplepie.inc");
149
	function textLimit($string, $length, $replacer = '...') {
150
	  if(strlen($string) > $length)
151
	  return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
152
	  return $string;
153
	}
154
	$feed = new SimplePie();
155
	$feed->set_cache_location("/tmp/simplepie/");
156
	$feed->set_feed_url($rss_feed_s);
157
	$feed->init();
158
	$feed->set_output_encoding('latin-1');
159
	$feed->handle_content_type();
160
	$counter = 1;
161
	foreach($feed->get_items() as $item) {
162
		$feed = $item->get_feed();
163
		$feed->strip_htmltags();
164
		echo "<a target='blank' href='" . $item->get_permalink() . "'>" . $item->get_title() . "</a><br />";
165
		$content = $item->get_content();
166
		$content = strip_tags($content);
167
		echo textLimit($content, $rsswidgettextlength) . "<br />";
168
		echo "Source: <a target='_blank' href='" . $item->get_permalink() . "'><img src='" . $feed->get_favicon() . "' alt='" . $feed->get_title() . "' title='" . $feed->get_title() . "' border='0' width='16' height='16' /></a><br />";
169
		$counter++;
170
		if($counter > $max_items)
171
			break;
172
		echo "<hr/>";
173
	}
174
?>
175
</div>
176

    
177
<!-- needed to display the widget settings menu -->
178
<script type="text/javascript">
179
//<![CDATA[
180
	selectIntLink = "rss-configure";
181
	textlink = document.getElementById(selectIntLink);
182
	textlink.style.display = "inline";
183
//]]>
184
</script>
(15-15/21)