2 local sys = require
"luci.sys"
3 local utl = require
"luci.util"
4 local fs = require
"luci.fs"
5 local i18n = require
"luci.i18n"
7 local title = data.title or i18n.translate(
"RSS")
8 local max = tonumber(data.max) or
10
10 local pr = data.paddingright or
"0"
12 local width = data.width or
"100%"
13 if type(width) ==
"number" then
16 local cachetime = tonumber(data.cache) or
3600
17 cachefile =
"/tmp/" .. name ..
".cache"
19 <div id=
"<%=name%>" style=
"width:<%=width%>;float:left">
20 <div style=
"padding-right: <%=pr%>">
24 <%:No url found in config%
>
26 local mtime = luci.fs.mtime(cachefile) or
0
28 expire = mtime + cachetime
30 if not fs.access(cachefile) or expire < now then
31 rss = sys.httpget(url)
34 <%:Could not get rss data from%
> <a href=
"<%=url%>"><%=url%
></a>
38 for item in string.gmatch(rss,
"<item>(.-)</item>") do
40 local title = item:match(
"<title>(.-)</title>")
41 local link = item:match(
"<link>(.-)</link>")
42 local desc = item:match(
"<description>(.-)</description>") or
""
43 if title and link then
44 table.insert(output, { title = utl.pcdata(title), link = utl.pcdata(link) })
49 local file = io.open(cachefile,
"w")
50 file:write(utl.serialize_data(output))
54 local file = assert(io.open(cachefile))
55 output = utl.restore_data(file:read'*a')
63 for k, v in ipairs(output) do
65 <li><a href=
"<%=v.link%>"><%=v.title%
></a></li>