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
bf8899ee
Commit
bf8899ee
authored
Jan 27, 2016
by
Ad Schellevis
Committed by
Franco Fichtner
Jan 27, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) refactor rss.widget.php, use latest SimplePie
(cherry picked from commit
e5c48cf6
)
parent
e25e9f10
Changes
1
Show 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 @
bf8899ee
<?php
/*
Copyright (C) 2014
Deciso B.V.
Copyright (C) 2014-2016
Deciso B.V.
Copyright (C) 2009 Scott Ullrich
Redistribution and use in source and binary forms, with or without
...
...
@@ -30,8 +30,18 @@ $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,45 +51,33 @@ 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=
""
/>
...
...
@@ -99,11 +97,10 @@ if ($config['widgets']['rssfeed']) {
<td>
<select
name=
'rssmaxitems'
id=
'rssmaxitems'
>
<option
value=
'
<?=
$max_items
?>
'
>
<?=
$max_items
?>
</option>
<?php
<?php
for
(
$x
=
100
;
$x
<
5100
;
$x
=
$x
+
100
)
{
echo
"<option value='
{
$x
}
'>
{
$x
}
</option>
\n
"
;
}
?>
}
?>
</select>
</td>
</tr>
...
...
@@ -114,11 +111,10 @@ if ($config['widgets']['rssfeed']) {
<td>
<select
name=
'rsswidgetheight'
id=
'rsswidgetheight'
>
<option
value=
'
<?=
$rsswidgetheight
?>
'
>
<?=
$rsswidgetheight
?>
px
</option>
<?php
<?php
for
(
$x
=
100
;
$x
<
5100
;
$x
=
$x
+
100
)
{
echo
"<option value='
{
$x
}
'>
{
$x
}
px</option>
\n
"
;
}
?>
}
?>
</select>
</td>
</tr>
...
...
@@ -129,11 +125,10 @@ if ($config['widgets']['rssfeed']) {
<td>
<select
name=
'rsswidgettextlength'
id=
'rsswidgettextlength'
>
<option
value=
'
<?=
$rsswidgettextlength
?>
'
>
<?=
$rsswidgettextlength
?>
</option>
<?php
<?php
for
(
$x
=
10
;
$x
<
5100
;
$x
=
$x
+
10
)
{
echo
"<option value='
{
$x
}
'>
{
$x
}
</option>
\n
"
;
}
?>
}
?>
</select>
</td>
</tr>
...
...
@@ -148,30 +143,20 @@ if ($config['widgets']['rssfeed']) {
<div
id=
"rss-widgets"
style=
"padding: 5px; height:
<?=
$rsswidgetheight
?>
px; overflow:scroll;"
>
<?php
if
(
!
is_dir
(
"/tmp/simplepie"
))
{
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
();
$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
);
...
...
@@ -182,7 +167,7 @@ foreach ($feed->get_items() as $item) {
break
;
}
echo
"<hr/>"
;
}
}
?>
</div>
...
...
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