3 LuCI - Lua Configuration Interface
5 Copyright
2012 Manuel Munz
<freifunk at somakoma dot de
>
7 Licensed under the Apache License, Version
2.0 (the
"License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-
2.0
15 local sys = require
"luci.sys"
16 local utl = require
"luci.util"
17 local fs = require
"luci.fs"
18 local i18n = require
"luci.i18n"
20 local title = data.title or i18n.translate(
"RSS")
21 local max = tonumber(data.max) or
10
23 local pr = data.paddingright or
"0"
25 local width = data.width or
"100%"
26 if type(width) ==
"number" then
29 local name = data['.name']
30 local cachetime = tonumber(data.cache) or
3600
31 cachefile =
"/tmp/" .. name ..
".cache"
33 <div id=
"<%=name%>" style=
"width:<%=width%>;float:left">
34 <div style=
"padding-right: <%=pr%>">
38 <%:No url found in config%
>
40 local mtime = luci.fs.mtime(cachefile) or
0
42 expire = mtime + cachetime
44 if not fs.access(cachefile) or expire < now then
45 rss = sys.httpget(url)
48 <%:Could not get rss data from%
> <a href=
"<%=url%>"><%=url%
></a>
52 for item in string.gmatch(rss,
"<item>(.-)</item>") do
54 local title = item:match(
"<title>(.-)</title>")
55 local link = item:match(
"<link>(.-)</link>")
56 local desc = item:match(
"<description>(.-)</description>") or
""
57 if title and link then
58 table.insert(output, { title = utl.pcdata(title), link = utl.pcdata(link) })
64 local file = io.open(cachefile,
"w")
65 file:write(utl.serialize_data(output))
70 local file = assert(io.open(cachefile))
71 output = utl.restore_data(file:read'*a')
78 <% for k, v in ipairs(output) do %
>
79 <li><a href=
"<%=v.link%>"><%=v.title%
></a></li>