]>
git.ipfire.org Git - ipfire.org.git/blob - www/web/__init__.py
3d58fb086c9420113274db6d043e18f9b0ae2402
2 # -*- coding: utf-8 -*-
8 import simplejson
as json
10 from http
import HTTPResponse
, WebError
17 self
.output
+= "%s\n" % s
24 def __init__(self
, file):
27 data
= data
.replace('\n', '') # Remove all \n
28 data
= data
.replace('\t', ' ') # Remove all \t
29 self
.json
= json
.loads(data
)
34 def include(self
, file):
38 self
.w(output
% self
.data
)
41 m
= Menu(self
.langs
.current
)
44 def __init__(self
, title
, content
, sidebar
=None):
47 self
.langs
= Languages()
48 self
.data
= {"server": os
.environ
["SERVER_NAME"].replace("ipfire", "<span>ipfire</span>"),
49 "title" : "%s - %s" % (os
.environ
["SERVER_NAME"], title
,),
51 "document_name" : title
,
52 "lang" : self
.langs
.current
,
53 "languages" : self
.langs
.menu(title
),
54 "year" : time
.strftime("%Y"),
55 "slogan" : "Security today!",
56 "content" : content(self
.langs
.current
),
59 self
.data
["sidebar"] = sidebar(self
.langs
.current
)
64 if self
.title
.endswith(".rss"):
65 self
.include("rss.inc")
66 type = "application/rss+xml"
68 self
.include("template.inc")
72 h
= HTTPResponse(code
, type=type)
73 h
.execute(self
.output
)
77 def __init__(self
, limit
=3):
78 Json
.__init
__(self
, "news.json")
80 for key
in sorted(self
.json
.keys()):
81 self
.news
.insert(0, self
.json
[key
])
83 self
.news
= self
.news
[:limit
]
85 def html(self
, lang
="en"):
87 for item
in self
.news
:
88 for i
in ("content", "subject",):
89 if type(item
[i
]) == type({}):
90 item
[i
] = item
[i
][lang
]
91 b
= Box(item
["subject"], "%(date)s - by %(author)s" % item
)
95 b
.w("""<p><a href="%(link)s" target="_blank">Read more.</a></p>""" % item
)
97 b
.w("""<p><a href="%(link)s" target="_blank">Mehr Informationen.</a></p>""" % item
)
103 def headlines(self
, lang
="en"):
105 for item
in self
.news
:
106 if type(item
["subject"]) == type({}):
107 item
["subject"] = item
["subject"][lang
]
108 headlines
.append((item
["subject"],))
116 def __init__(self
, lang
):
118 Json
.__init
__(self
, "menu.json")
121 s
= """<div id="menu"><ul>\n"""
122 for item
in self
.json
.values():
126 if type(item
["name"]) == type({}):
127 item
["name"] = item
["name"][self
.lang
]
129 # Add language attribute to local uris
130 if item
["uri"].startswith("/"):
131 item
["uri"] = "/%s%s" % (self
.lang
, item
["uri"],)
133 if os
.environ
["REQUEST_URI"].endswith(item
["uri"]):
134 item
["active"] = "class=\"active\""
136 s
+= """<li><a href="%(uri)s" %(active)s>%(name)s</a></li>\n""" % item
142 def __init__(self
, lang
="en"):
144 Json
.__init
__(self
, "banners.json")
147 banner
= random
.choice(self
.json
.values())
152 def __init__(self
, doc
=""):
155 for lang
in ("de", "en",):
158 self
.current
= cgi
.FieldStorage().getfirst("lang") or "en"
160 def append(self
, lang
):
161 self
.available
.append(lang
)
165 for lang
in self
.available
:
166 s
+= """<a href="/%(lang)s/%(doc)s"><img src="/images/%(lang)s.gif" alt="%(lang)s" /></a>""" % \
167 { "lang" : lang
, "doc" : doc
, }
172 def __init__(self
, headline
, subtitle
=""):
174 self
.w("""<div class="post"><h3>%s</h3>""" % (headline
,))
176 self
.w("""<div class="post_info">%s</div>""" % (subtitle
,))
179 self
.w("""<br class="clear" /></div>""")
180 return Data
.__call
__(self
)
184 def __init__(self
, name
):
187 def content(self
, lang
):
188 #self.w("""<h4>Test Page</h4>
189 # <p>Lorem ipsum dolor sit amet, consectetuer sadipscing elitr,
190 # sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
191 # aliquyam erat, sed diam voluptua. At vero eos et accusam et justo
192 # duo dolores et ea rebum.</p>""")
194 self
.w("""<h4>%(title)s</h4><a href="%(link)s" target="_blank">
195 <img class="banner" src="%(uri)s" /></a>""" % banners
.random())
197 def __call__(self
, lang
):
199 return Data
.__call
__(self
)
203 def __init__(self
, name
):
207 self
.w("""<h3>Test Page</h3>
208 <p>Lorem ipsum dolor sit amet, consectetuer sadipscing elitr,
209 sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
210 aliquyam erat, sed diam voluptua. At vero eos et accusam et justo
211 duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
212 sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
213 consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
214 ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
215 eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
216 gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
217 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
218 nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
219 sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
220 rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
221 ipsum dolor sit amet.</p>""")
223 b
= Box("Test box one", "Subtitle of box")
224 b
.write("""<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit
225 esse molestie consequat, vel illum dolore eu feugiat nulla facilisis
226 at vero eros et accumsan et iusto odio dignissim qui blandit praesent
227 luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
228 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
229 nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
233 b
= Box("Test box two", "Subtitle of box")
234 b
.write("""<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
235 suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem
236 vel eum iriure dolor in hendrerit in vulputate velit esse molestie
237 consequat, vel illum dolore eu feugiat nulla facilisis at vero eros
238 et accumsan et iusto odio dignissim qui blandit praesent luptatum
239 zzril delenit augue duis dolore te feugait nulla facilisi.</p>""")
242 def __call__(self
, lang
="en"):
244 return Data
.__call
__(self
)