]>
git.ipfire.org Git - ipfire.org.git/blob - www/web/__init__.py
2 # -*- coding: utf-8 -*-
8 import simplejson
as json
10 from http
import HTTPResponse
, WebError
20 self
.output
+= "%s\n" % s
27 def __init__(self
, file):
30 data
= data
.replace('\n', '') # Remove all \n
31 data
= data
.replace('\t', ' ') # Remove all \t
32 self
.json
= json
.loads(data
)
37 def include(self
, file):
41 self
.w(output
% self
.data
)
44 m
= Menu(self
.langs
.current
)
47 def __init__(self
, title
, content
, sidebar
=None):
50 self
.langs
= Languages()
51 self
.data
= {"server": os
.environ
["SERVER_NAME"].replace("ipfire", "<span>ipfire</span>"),
52 "title" : "%s - %s" % (os
.environ
["SERVER_NAME"], title
,),
54 "document_name" : title
,
55 "lang" : self
.langs
.current
,
56 "languages" : self
.langs
.menu(title
),
57 "year" : time
.strftime("%Y"),
58 "slogan" : "Security today!",
59 "content" : content(self
.langs
.current
),
62 self
.data
["sidebar"] = sidebar(self
.langs
.current
)
67 if self
.title
.endswith(".rss"):
68 self
.include("rss.inc")
69 type = "application/rss+xml"
71 self
.include("template.inc")
75 h
= HTTPResponse(code
, type=type)
76 h
.execute(self
.output
)
80 def __init__(self
, limit
=3):
81 Json
.__init
__(self
, "news.json")
83 for key
in sorted(self
.json
.keys()):
84 self
.news
.insert(0, self
.json
[key
])
86 self
.news
= self
.news
[:limit
]
88 def html(self
, lang
="en"):
90 for item
in self
.news
:
91 for i
in ("content", "subject",):
92 if type(item
[i
]) == type({}):
93 item
[i
] = item
[i
][lang
]
94 b
= Box(item
["subject"], "%(date)s - by %(author)s" % item
)
98 b
.w("""<p><a href="%(link)s" target="_blank">Read more.</a></p>""" % item
)
100 b
.w("""<p><a href="%(link)s" target="_blank">Mehr Informationen.</a></p>""" % item
)
106 def headlines(self
, lang
="en"):
108 for item
in self
.news
:
109 if type(item
["subject"]) == type({}):
110 item
["subject"] = item
["subject"][lang
]
111 headlines
.append((item
["subject"],))
119 def __init__(self
, lang
):
121 Json
.__init
__(self
, "menu.json")
124 s
= """<div id="menu"><ul>\n"""
125 for item
in self
.json
.values():
129 if type(item
["name"]) == type({}):
130 item
["name"] = item
["name"][self
.lang
]
132 # Add language attribute to local uris
133 if item
["uri"].startswith("/"):
134 item
["uri"] = "/%s%s" % (self
.lang
, item
["uri"],)
136 if os
.environ
["REQUEST_URI"].endswith(item
["uri"]):
137 item
["active"] = "class=\"active\""
139 s
+= """<li><a href="%(uri)s" %(active)s>%(name)s</a></li>\n""" % item
145 def __init__(self
, lang
="en"):
147 Json
.__init
__(self
, "banners.json")
150 banner
= random
.choice(self
.json
.values())
155 def __init__(self
, doc
=""):
158 for lang
in ("de", "en",):
161 self
.current
= cgi
.FieldStorage().getfirst("lang") or "en"
163 def append(self
, lang
):
164 self
.available
.append(lang
)
168 for lang
in self
.available
:
169 s
+= """<a href="/%(lang)s/%(doc)s"><img src="/images/%(lang)s.gif" alt="%(lang)s" /></a>""" % \
170 { "lang" : lang
, "doc" : doc
, }
175 def __init__(self
, headline
, subtitle
=""):
177 self
.w("""<div class="post"><h3>%s</h3><a name="%s"></a>""" % (headline
,headline
,))
179 self
.w("""<div class="post_info">%s</div>""" % (subtitle
,))
182 self
.w("""<br class="clear" /></div>""")
183 return Data
.__call
__(self
)
187 def __init__(self
, name
):
190 def content(self
, lang
):
191 #self.w("""<h4>Test Page</h4>
192 # <p>Lorem ipsum dolor sit amet, consectetuer sadipscing elitr,
193 # sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
194 # aliquyam erat, sed diam voluptua. At vero eos et accusam et justo
195 # duo dolores et ea rebum.</p>""")
197 self
.w("""<h4>%(title)s</h4><a href="%(link)s" target="_blank">
198 <img class="banner" src="%(uri)s" /></a>""" % banners
.random())
200 def __call__(self
, lang
):
202 return Data
.__call
__(self
)
206 def __init__(self
, name
):
210 self
.w("""<h3>Test Page</h3>
211 <p>Lorem ipsum dolor sit amet, consectetuer sadipscing elitr,
212 sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
213 aliquyam erat, sed diam voluptua. At vero eos et accusam et justo
214 duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
215 sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
216 consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
217 ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
218 eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
219 gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
220 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
221 nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
222 sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
223 rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
224 ipsum dolor sit amet.</p>""")
226 b
= Box("Test box one", "Subtitle of box")
227 b
.write("""<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit
228 esse molestie consequat, vel illum dolore eu feugiat nulla facilisis
229 at vero eros et accumsan et iusto odio dignissim qui blandit praesent
230 luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
231 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
232 nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
236 b
= Box("Test box two", "Subtitle of box")
237 b
.write("""<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
238 suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem
239 vel eum iriure dolor in hendrerit in vulputate velit esse molestie
240 consequat, vel illum dolore eu feugiat nulla facilisis at vero eros
241 et accumsan et iusto odio dignissim qui blandit praesent luptatum
242 zzril delenit augue duis dolore te feugait nulla facilisi.</p>""")
245 def __call__(self
, lang
="en"):
247 return Data
.__call
__(self
)