Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
e5c48cf6
Commit
e5c48cf6
authored
Jan 27, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) refactor rss.widget.php, use latest SimplePie
parent
bf229dff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
120 additions
and
135 deletions
+120
-135
rss.widget.php
src/www/widgets/widgets/rss.widget.php
+120
-135
No files found.
src/www/widgets/widgets/rss.widget.php
View file @
e5c48cf6
<?php
/*
Copyright (C) 2014
Deciso B.V.
Copyright (C) 2009 Scott Ullrich
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014-2016
Deciso B.V.
Copyright (C) 2009 Scott Ullrich
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
$nocsrf
=
true
;
require_once
(
"guiconfig.inc"
);
require_once
(
"pfsense-utils.inc"
);
require_once
(
"simplepie/autoloader.php"
);
require_once
(
"simplepie/idn/idna_convert.class.php"
);
if
(
$_POST
[
'rssfeed'
])
{
function
textLimit
(
$string
,
$length
,
$replacer
=
'...'
)
{
if
(
strlen
(
$string
)
>
$length
)
{
return
(
preg_match
(
'/^(.*)\W.*$/'
,
substr
(
$string
,
0
,
$length
+
1
),
$matches
)
?
$matches
[
1
]
:
substr
(
$string
,
0
,
$length
))
.
$replacer
;
}
return
$string
;
}
if
(
!
empty
(
$_POST
[
'rssfeed'
]))
{
$config
[
'widgets'
][
'rssfeed'
]
=
str_replace
(
"
\n
"
,
","
,
htmlspecialchars
(
$_POST
[
'rssfeed'
],
ENT_QUOTES
|
ENT_HTML401
));
$config
[
'widgets'
][
'rssmaxitems'
]
=
str_replace
(
"
\n
"
,
","
,
htmlspecialchars
(
$_POST
[
'rssmaxitems'
],
ENT_QUOTES
|
ENT_HTML401
));
$config
[
'widgets'
][
'rsswidgetheight'
]
=
htmlspecialchars
(
$_POST
[
'rsswidgetheight'
],
ENT_QUOTES
|
ENT_HTML401
);
...
...
@@ -41,156 +51,131 @@ if ($_POST['rssfeed']) {
}
// Use saved feed and max items
if
(
$config
[
'widgets'
][
'rssfeed'
]
)
{
if
(
!
empty
(
$config
[
'widgets'
][
'rssfeed'
])
)
{
$rss_feed_s
=
explode
(
","
,
$config
[
'widgets'
][
'rssfeed'
]);
}
if
(
$config
[
'widgets'
][
'rssmaxitems'
])
{
$max_items
=
$config
[
'widgets'
][
'rssmaxitems'
];
}
if
(
is_numeric
(
$config
[
'widgets'
][
'rsswidgetheight'
]))
{
$rsswidgetheight
=
$config
[
'widgets'
][
'rsswidgetheight'
];
}
if
(
is_numeric
(
$config
[
'widgets'
][
'rsswidgettextlength'
]))
{
$rsswidgettextlength
=
$config
[
'widgets'
][
'rsswidgettextlength'
];
}
// Set a default feed if none exists
if
(
!
$rss_feed_s
)
{
$textarea_txt
=
str_replace
(
","
,
"
\n
"
,
$config
[
'widgets'
][
'rssfeed'
]);
}
else
{
// Set a default feed if none exists
$rss_feed_s
=
"https://opnsense.org/feed/"
;
$config
[
'widgets'
][
'rssfeed'
]
=
"https://opnsense.org/feed/"
;
$textarea_txt
=
""
;
}
if
(
!
$max_items
)
{
if
(
!
empty
(
$config
[
'widgets'
][
'rssmaxitems'
])
&&
is_numeric
(
$config
[
'widgets'
][
'rssmaxitems'
]))
{
$max_items
=
$config
[
'widgets'
][
'rssmaxitems'
];
}
else
{
$max_items
=
10
;
}
if
(
!
$rsswidgetheight
)
{
if
(
!
empty
(
$config
[
'widgets'
][
'rsswidgetheight'
])
&&
is_numeric
(
$config
[
'widgets'
][
'rsswidgetheight'
]))
{
$rsswidgetheight
=
$config
[
'widgets'
][
'rsswidgetheight'
];
}
else
{
$rsswidgetheight
=
300
;
}
if
(
!
$rsswidgettextlength
)
{
$rsswidgettextlength
=
140
;
// oh twitter, how do we love thee?
}
if
(
$config
[
'widgets'
][
'rssfeed'
])
{
$textarea_txt
=
str_replace
(
","
,
"
\n
"
,
$config
[
'widgets'
][
'rssfeed'
]);
if
(
!
empty
(
$config
[
'widgets'
][
'rsswidgettextlength'
])
&&
is_numeric
(
$config
[
'widgets'
][
'rsswidgettextlength'
]))
{
$rsswidgettextlength
=
$config
[
'widgets'
][
'rsswidgettextlength'
];
}
else
{
$
textarea_txt
=
""
;
$
rsswidgettextlength
=
140
;
// oh twitter, how do we love thee?
}
?>
<input
type=
"hidden"
id=
"rss-config"
name=
"rss-config"
value=
""
/>
<div
id=
"rss-settings"
class=
"widgetconfigdiv"
style=
"display:none;"
>
<form
action=
"/widgets/widgets/rss.widget.php"
method=
"post"
name=
"iformc"
>
<table
class=
"table table-striped"
summary=
"rss widget"
>
<tr>
<td
colspan=
"2"
>
<textarea
name=
"rssfeed"
class=
"formfld unknown textarea_widget"
id=
"rssfeed"
cols=
"40"
rows=
"3"
style=
"max-width:100%;"
>
<?=
$textarea_txt
;
?>
</textarea>
</td>
</tr>
<tr>
<td>
<form
action=
"/widgets/widgets/rss.widget.php"
method=
"post"
name=
"iformc"
>
<table
class=
"table table-striped"
summary=
"rss widget"
>
<tr>
<td
colspan=
"2"
>
<textarea
name=
"rssfeed"
class=
"formfld unknown textarea_widget"
id=
"rssfeed"
cols=
"40"
rows=
"3"
style=
"max-width:100%;"
>
<?=
$textarea_txt
;
?>
</textarea>
</td>
</tr>
<tr>
<td>
<?=
gettext
(
'Display number of items:'
)
?>
</td>
<td>
<select
name=
'rssmaxitems'
id=
'rssmaxitems'
>
<option
value=
'
<?=
$max_items
?>
'
>
<?=
$max_items
?>
</option>
<?php
for
(
$x
=
100
;
$x
<
5100
;
$x
=
$x
+
100
)
{
echo
"<option value='
{
$x
}
'>
{
$x
}
</option>
\n
"
;
}
?>
</select>
</td>
</tr>
<tr>
<td>
</td>
<td>
<select
name=
'rssmaxitems'
id=
'rssmaxitems'
>
<option
value=
'
<?=
$max_items
?>
'
>
<?=
$max_items
?>
</option>
<?php
for
(
$x
=
100
;
$x
<
5100
;
$x
=
$x
+
100
)
{
echo
"<option value='
{
$x
}
'>
{
$x
}
</option>
\n
"
;
}
?>
</select>
</td>
</tr>
<tr>
<td>
<?=
gettext
(
'Widget height:'
)
?>
</td>
<td>
<select
name=
'rsswidgetheight'
id=
'rsswidgetheight'
>
<option
value=
'
<?=
$rsswidgetheight
?>
'
>
<?=
$rsswidgetheight
?>
px
</option>
<?php
for
(
$x
=
100
;
$x
<
5100
;
$x
=
$x
+
100
)
{
echo
"<option value='
{
$x
}
'>
{
$x
}
px</option>
\n
"
;
}
?>
</select>
</td>
</tr>
<tr>
<td>
</td>
<td>
<select
name=
'rsswidgetheight'
id=
'rsswidgetheight'
>
<option
value=
'
<?=
$rsswidgetheight
?>
'
>
<?=
$rsswidgetheight
?>
px
</option>
<?php
for
(
$x
=
100
;
$x
<
5100
;
$x
=
$x
+
100
)
{
echo
"<option value='
{
$x
}
'>
{
$x
}
px</option>
\n
"
;
}
?>
</select>
</td>
</tr>
<tr>
<td>
<?=
gettext
(
'Show how many characters from story:'
)
?>
</td>
<td>
<select
name=
'rsswidgettextlength'
id=
'rsswidgettextlength'
>
<option
value=
'
<?=
$rsswidgettextlength
?>
'
>
<?=
$rsswidgettextlength
?>
</option>
<?php
for
(
$x
=
10
;
$x
<
5100
;
$x
=
$x
+
10
)
{
echo
"<option value='
{
$x
}
'>
{
$x
}
</option>
\n
"
;
}
?>
</select>
</td>
</tr>
<tr>
<td
colspan=
"2"
>
<input
id=
"submitc"
name=
"submitc"
type=
"submit"
class=
"btn btn-primary formbtn"
value=
"
<?=
gettext
(
'Save'
)
?>
"
/>
</td>
</tr>
</table>
</form>
</td>
<td>
<select
name=
'rsswidgettextlength'
id=
'rsswidgettextlength'
>
<option
value=
'
<?=
$rsswidgettextlength
?>
'
>
<?=
$rsswidgettextlength
?>
</option>
<?php
for
(
$x
=
10
;
$x
<
5100
;
$x
=
$x
+
10
)
{
echo
"<option value='
{
$x
}
'>
{
$x
}
</option>
\n
"
;
}
?>
</select>
</td>
</tr>
<tr>
<td
colspan=
"2"
>
<input
id=
"submitc"
name=
"submitc"
type=
"submit"
class=
"btn btn-primary formbtn"
value=
"
<?=
gettext
(
'Save'
)
?>
"
/>
</td>
</tr>
</table>
</form>
</div>
<div
id=
"rss-widgets"
style=
"padding: 5px; height:
<?=
$rsswidgetheight
?>
px; overflow:scroll;"
>
<?php
if
(
!
is_dir
(
"/tmp/simplepie"
))
{
mkdir
(
"/tmp/simplepie"
);
mkdir
(
"/tmp/simplepie/cache"
);
}
if
(
!
is_dir
(
"/tmp/simplepie"
))
{
mkdir
(
"/tmp/simplepie"
);
mkdir
(
"/tmp/simplepie/cache"
);
}
exec
(
"chmod a+rw /tmp/simplepie/."
);
exec
(
"chmod a+rw /tmp/simplepie/cache/."
);
require_once
(
"simplepie/simplepie.inc"
);
function
textLimit
(
$string
,
$length
,
$replacer
=
'...'
)
{
if
(
strlen
(
$string
)
>
$length
)
{
return
(
preg_match
(
'/^(.*)\W.*$/'
,
substr
(
$string
,
0
,
$length
+
1
),
$matches
)
?
$matches
[
1
]
:
substr
(
$string
,
0
,
$length
))
.
$replacer
;
}
return
$string
;
}
$feed
=
new
SimplePie
();
$feed
->
set_cache_location
(
"/tmp/simplepie/"
);
$feed
->
set_feed_url
(
$rss_feed_s
);
$feed
->
init
();
$feed
->
set_output_encoding
(
'latin-1'
);
$feed
->
handle_content_type
();
$counter
=
1
;
foreach
(
$feed
->
get_items
()
as
$item
)
{
$feed
=
$item
->
get_feed
();
$feed
->
strip_htmltags
();
echo
"<a target='blank' href='"
.
$item
->
get_permalink
()
.
"'>"
.
$item
->
get_title
()
.
"</a><br />"
;
$content
=
$item
->
get_content
();
$content
=
strip_tags
(
$content
);
echo
textLimit
(
$content
,
$rsswidgettextlength
)
.
"<br />"
;
echo
"Source: <a target='_blank' href='"
.
$item
->
get_permalink
()
.
"'>"
.
$feed
->
get_title
()
.
"</a><br />"
;
$counter
++
;
if
(
$counter
>
$max_items
)
{
break
;
$counter
=
1
;
foreach
(
$feed
->
get_items
()
as
$item
)
{
echo
"<a target='blank' href='"
.
$item
->
get_permalink
()
.
"'>"
.
$item
->
get_title
()
.
"</a><br />"
;
$content
=
$item
->
get_content
();
$content
=
strip_tags
(
$content
);
echo
textLimit
(
$content
,
$rsswidgettextlength
)
.
"<br />"
;
echo
"Source: <a target='_blank' href='"
.
$item
->
get_permalink
()
.
"'>"
.
$feed
->
get_title
()
.
"</a><br />"
;
$counter
++
;
if
(
$counter
>
$max_items
)
{
break
;
}
echo
"<hr/>"
;
}
echo
"<hr/>"
;
}
?>
</div>
<!-- needed to display the widget settings menu -->
<script
type=
"text/javascript"
>
//
<!
[
CDATA
[
selectIntLink
=
"
rss-configure
"
;
textlink
=
document
.
getElementById
(
selectIntLink
);
textlink
.
style
.
display
=
"
inline
"
;
selectIntLink
=
"
rss-configure
"
;
textlink
=
document
.
getElementById
(
selectIntLink
);
textlink
.
style
.
display
=
"
inline
"
;
//]]>
</script>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment