modules/freifunk: include widgets in indexpage when available
[project/luci.git] / modules / freifunk / luasrc / view / freifunk / index.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15 <%+header%>
16 <% 
17 local uci = require "luci.model.uci".cursor()
18 local tpl = require "luci.template"
19 local fs = require "luci.fs"
20 local ff = {}
21 local ff = uci:get_all("freifunk")
22
23 if not ff or not ff.community.name then
24         community = "Freifunk"
25         DefaultText = ""
26         nickname = "No Nickname set"
27 else
28         community = ff.community.name
29         DefaultText = ff.community.DefaultText
30         nickname = ff.contact.nickname
31 end
32
33 local co = "profile_" .. community
34 --local community = uci:get_first(co, "community", "name") or "Freifunk"
35 local url = uci:get_first(co, "community", "homepage") or "http://www.freifunk.net"
36
37
38 local usertext = fs.readfile("/www/luci-static/index_user.html")
39
40 if DefaultText ~= "disabled" then
41
42         defaulttext = '<h2><a id="content" name="content">'..
43         (translate("Hello and welcome in the network of"))..
44         ' '..
45         (community or "Freifunk Deutschland")..
46         '!</a></h2><p>'..
47         translate("We are an initiative to establish a free, independent and open wireless mesh network.")..
48         '<br />'..
49         translate("This is the access point")..
50         ' '..
51         luci.sys.hostname()..
52         '. '..
53         translate("It is operated by")..
54         ' <a href="'..
55         luci.dispatcher.build_url("freifunk", "contact")..
56         '">'..
57         (nickname or translate("Please set your contact information"))..
58         '</a>.</p><p>'..
59         translate("You can find further information about the global Freifunk initiative at")..
60         ' <a href="http://freifunk.net">Freifunk.net</a>.<br />'..
61         translate("If you are interested in our project then contact the local community")..
62         ' <a href="'..url..'">'..community..'</a>.</p><p><strong>'..
63         translate("Notice")..
64         '</strong>: '..
65         translate("Internet access depends on technical and organisational conditions and may or may not work for you.")..
66         '</p>'
67 end
68 %>
69
70 <%=defaulttext%>
71 <%=usertext%>
72
73 <%
74 -- add custom widgets from view/freifunk/widgets
75 local widgets = {}
76 local dir = "/usr/lib/lua/luci/view/freifunk/widgets"
77
78 uci:foreach("freifunk-widgets", "widget",
79                         function(s)
80                                 if s.enabled == "1" then
81                                         local name = s[".name"] 
82                                         widgets[name] = s
83                                 end
84                         end)
85
86 local function cmp(a, b)
87         return (widgets[a].order or 100) > (widgets[b].order or 100)
88 end
89
90 for k, v in luci.util.spairs(widgets, function(a,b) return (tonumber(widgets[a].order) < tonumber(widgets[b].order)) end) do
91         if v['template'] and fs.access(dir .. "/" .. v['template'] .. "/main.htm") then
92                 tpl.render("freifunk/widgets/" .. v['template'] .. "/main", { name = k, data = v })
93         end
94 end
95
96 %>
97 <%+footer%>