<% --[[ LuCI - Lua Configuration Interface Copyright 2012 Manuel Munz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 ]]-- local sys = require "luci.sys" local utl = require "luci.util" local fs = require "nixio.fs" local i18n = require "luci.i18n" local url = data.url local title = data.title or i18n.translate("RSS") local max = tonumber(data.max) or 10 local rss local pr = data.paddingright or "0" local output = {} local width = data.width or "100%" if type(width) == "number" then width = width .. "px" end local name = data['.name'] local cachetime = tonumber(data.cache) or 3600 cachefile = "/tmp/" .. name .. ".cache" %>

<%=title%>

<% if not url then %> <%:No url found in config%> <% else local mtime = fs.stat(cachefile, "mtime") or 0 local now = os.time() expire = mtime + cachetime if not fs.access(cachefile) or expire < now then rss = sys.httpget(url) if #rss == 0 then %> <%:Could not get rss data from%> <%=url%> <% else local count = 0 for item in string.gmatch(rss, "(.-)") do if count < max then local title = item:match("(.-)") local link = item:match("(.-)") local desc = item:match("(.-)") or "" if title and link then table.insert(output, { title = utl.pcdata(title), link = utl.pcdata(link) }) end count = count + 1 end end if count > 0 then local file = io.open(cachefile, "w") file:write(utl.serialize_data(output)) file:close() end end else local file = assert(io.open(cachefile)) output = utl.restore_data(file:read'*a') end end if #output > 0 then %>
    <% for k, v in ipairs(output) do %>
  • <%=v.title%>
  • <% end %>
<%end%>