1 import urllib2, cookielib
2
3 from MoinMoin.theme.modern import Theme as ThemeBase
4 from MoinMoin.Page import Page
5 from MoinMoin import wikiutil
6 from MoinMoin import log
7 logging = log.getLogger(__name__)
8
9 class Theme(ThemeBase):
10 name = "joomla_theme"
11
12 def send_title(self, text, **keywords):
13 self.request._joomla_theme_end = u''
14 jar = cookielib.CookieJar()
15 cookiehdr = self.request.saved_cookie
16 req = urllib2.Request(url=self.request.cfg.joomla_theme_url)
17 req.add_header('Cookie', cookiehdr)
18 req.add_header('User-Agent', self.request.http_user_agent)
19 req.add_header('X-Forwarded-From', self.request.remote_addr)
20 req.add_header('Host', self.request.cfg.joomla_theme_host)
21 data = urllib2.urlopen(req).read()
22 data = data.decode(self.request.cfg.joomla_charset)
23 returnto = 'input type="hidden" name="return" value="%s"' % self.request.cfg.joomla_theme_orig_returnto
24 realreturnto = 'input type="hidden" name="return" value="%s"' % self.request.request_uri
25 data = data.replace(returnto, realreturnto)
26 start, data = data.split('<!-- Content -->')
27 start = start.replace(self.request.cfg.joomla_charset, 'utf-8')
28 start = start.replace('MoinMoinTitle', text)
29 mid, end = data.split('<!-- /Content -->')
30
31
32 txt = self.request.redirectedOutput(ThemeBase.send_title, self, text, **keywords)
33 dummy, txt = txt.split('</title>', 2)
34 head, txt = txt.split('</head>', 2)
35 dummy, body = txt.split('<div id="header">')
36 self.request._joomla_theme_end = end
37 start = start.replace('</head>', head + '</head>')
38 self.request.write(start)
39 self.request.write('<div id="moincontent">')
40 self.request.write('<div id="header">')
41 self.request.write(body)
42
43 def send_footer(self, pagename, **kw):
44
45
46 footer = self.request._joomla_theme_end
47 self.request._joomla_theme_end = u''
48 ThemeBase.send_footer(self, pagename, **kw)
49 self.request.write('</div>')
50 self.request.write(footer)
51
52 def header(self, d, **kw):
53 html = [
54
55 self.emit_custom_html(self.cfg.page_header1),
56
57
58 u'<div id="header">',
59 self.msg(d),
60 self.editbar(d),
61 u'</div>',
62
63 self.emit_custom_html(self.cfg.page_header2),
64 self.startPage(),
65 ]
66 return u'\n'.join(html)
67
68 def editorheader(self, d, **kw):
69 html = [
70 self.emit_custom_html(self.cfg.page_header1),
71 u'<div id="header">',
72 self.msg(d),
73 u'</div>',
74
75 self.emit_custom_html(self.cfg.page_header2),
76 self.startPage(),
77 ]
78 return u'\n'.join(html)
79
80 def footer(self, d, **keywords):
81 page = d['page']
82 html = [
83 self.pageinfo(page),
84 self.endPage(),
85
86 self.emit_custom_html(self.cfg.page_footer1),
87 self.emit_custom_html(self.cfg.page_footer2),
88 ]
89 return u'\n'.join(html)
90
91 def send_closing_html(self):
92 return u''
93
94 def execute(request):
95 return Theme(request)